copy: fix file concatenation when invoked via COMMAND /C#117
Merged
stsp merged 1 commit intodosemu2:masterfrom Feb 5, 2026
Merged
copy: fix file concatenation when invoked via COMMAND /C#117stsp merged 1 commit intodosemu2:masterfrom
stsp merged 1 commit intodosemu2:masterfrom
Conversation
tgies
added a commit
to tgies/MS-DOS
that referenced
this pull request
Feb 4, 2026
Workaround for dosemu2/comcom64#117 - the copy command fails with 'Source and destination cannot match' when using file concatenation (copy a+b dest) via COMMAND /C, which breaks the IO.SYS build step.
The COPY command with file concatenation (e.g., `copy /b a+b dest`) fails with "Source and destination cannot match" when invoked via `COMMAND /C`, such as when nmake executes makefile commands. Root cause: The /C handler builds cmd_line by concatenating argv elements with spaces, always adding a trailing space after the last argument. In expand_pluses(), `strrchr(cmd_args, ' ')` then finds this trailing space instead of the space before the destination filename, causing the destination to be effectively empty. Example with trailing space from /C: Input: "/b msload.com+msbio.cl1 io.sys " last_arg = strrchr(..., ' ') -> points to trailing " " Output: "/b msload.com ;msbio.cl1 io.sys " Result: first file group has no destination, defaults to source This bug was introduced in commit 234e221 ("copy: support any amount of pluses [fixes dosemu2#94]"). The previous implementation was immune to trailing spaces because it used forward-searching (strchr from after the +) rather than backward-searching (strrchr from end of string). Fix: Strip trailing spaces from cmd_args_bkp before finding last_arg.
66f44d9 to
b4c6759
Compare
Member
|
I believe the CI patch went |
Contributor
Author
|
The CI patch isn't part of this PR -- GitHub is just showing it in the summary because I referenced this PR from a separate commit in my tgies/MS-DOS repo. "tgies added a commit to tgies/MS-DOS that referenced this pull request" |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The COPY command with file concatenation (e.g.,
copy /b a+b dest) fails with "Source and destination cannot match" when invoked viaCOMMAND /C, such as when nmake executes makefile commands.Root cause: The /C handler builds cmd_line by concatenating argv elements with spaces, always adding a trailing space after the last argument. In
expand_pluses(),strrchr(cmd_args, ' ')then finds this trailing space instead of the space before the destination filename, causing the destination to be effectively empty.Example with trailing space from /C:
This bug was introduced in commit 234e221 ("copy: support any amount of pluses [fixes #94]"). The previous implementation was immune to trailing spaces because it used forward-searching (
strchrfrom after the+) rather than backward-searching (strrchrfrom end of string).Fix:
+in cmd_args (restores old behavior for simple copy commands)cmd_args_bkpbefore findinglast_argThe early exit is necessary because stripping trailing spaces from a single-argument copy like
copy file(which becomescopy filevia COMMAND /C) would leave no spaces, causing a spurious "syntax error".