Bug 4356 - windres fails on files with spaces
Summary: windres fails on files with spaces
Status: WAITING
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.16
: P2 critical
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-13 15:51 UTC by Hendrik Sattler
Modified: 2016-03-13 22:40 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Put filenames from command line in quotes to handle spaces correctly (514 bytes, patch)
2007-04-20 16:31 UTC, Hendrik Sattler
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hendrik Sattler 2007-04-13 15:51:38 UTC
Hi,

Windres is very limited on common windows systems because it cannot handle 
pathes with spaces.
Hint: the default homedir contains spaces

This does not seem to be fixed in latest CVS because the error is most 
obviously in binutils/resrc.c (and similar) in function read_rc_file() and 
look_for_default():
sprintf (cmd, "%s %s %s", preprocessor, preprocargs, filename);

The filename argument MUST be surrounded by "", thus this line should read:
sprintf (cmd, "%s %s \"%s\"", preprocessor, preprocargs, filename);

Easy fix, I'd say. Reproducable on command line using DEFAULT_PREPROCESSOR.

HS
Comment 1 Nick Clifton 2007-04-20 14:24:14 UTC
Subject: Re:  New: windres fails on files with spaces

Hi HS,

> This does not seem to be fixed in latest CVS because the error is most 
> obviously in binutils/resrc.c (and similar) in function read_rc_file() and 
> look_for_default():
> sprintf (cmd, "%s %s %s", preprocessor, preprocargs, filename);
> 
> The filename argument MUST be surrounded by "", thus this line should read:
> sprintf (cmd, "%s %s \"%s\"", preprocessor, preprocargs, filename);
> 
> Easy fix, I'd say.

Would you like to submit a patch that does this then ?

> Reproducable on command line using DEFAULT_PREPROCESSOR.

Please could you provide an example of such a command line ?

Cheers
   Nick


Comment 2 Hendrik Sattler 2007-04-20 16:31:24 UTC
Created attachment 1730 [details]
Put filenames from command line in quotes to handle spaces correctly

> Please could you provide an example of such a command line?

Just specify a full path with spaces in it:
C:\>windres "C:\test with spaces\gui.rc" "c:\test with spaces"\gui.obj
gcc: C:\test: No such file or directory
gcc: with: No such file or directory
gcc: spaces\gui.rc: No such file or directory
gcc: warning: `-x c' after last input file has no effect
gcc: no input files
windres: no resources

Same for the parameter -I. The patch fixes those issue.

NOTE:
This is still broken for file names that use special shell characters.
This is because you use popen() instead of a combination of pipe(), fork(), a
flavour of exec() and fdopen().
The latter one does not have any of those issues because the shell is avoided
(hey, it will even be faster).
So, see this patch as hotfix for common usage. A bit more work is needed to
allow shell specific characters in file name.

HS

PS: popen() is an _evil_ command!
Comment 3 Nick Clifton 2007-06-06 08:07:03 UTC
Hi Hendrik,

  This problem should now be resolved.  A recent patch to resrc.c should ensure
that all special case filenames are quoted when they are used on generated
command lines.

Cheers
  Nick
Comment 4 Oisín 2011-02-28 18:31:10 UTC
It does not seem to be fixed in 2.21; calling windres with the following:

--include-dir "C:\Program Files\Lua\5.1\include"

Produces:

"gcc: Files\Lua\5.1\include: No such file or directory
windres: gcc exited with status 1"

Using single quotes instead of double quotes causes a different error; I'm not sure if they have another special meaning.

I can work around it with:

--include-dir "C:\Progra~1\Lua\5.1\include"

But it'd be better if it worked the normal way.
Comment 5 Hendrik Sattler 2011-03-01 07:56:18 UTC
The fix is equally simple, though, this time in windres.c:
-I%s  -> -I\"%s\"
Comment 6 Hendrik Sattler 2011-03-01 07:57:34 UTC
The include options are also affected, reopening bug...
Comment 7 spring 2014-07-06 21:17:49 UTC
i hit this bug, too...

GNU windres (GNU Binutils) 2.23.1
Comment 8 spring 2014-07-06 21:21:19 UTC
> "C:\Program Files (x86)\CODEBL~1\MinGW\bin\windres.exe"  -O coff D:/spring/rts/icon.rc rts/builds/legacy/CMakeFiles/engine-legacy.dir/__/__/icon.rc.obj
Der Befehl "C:\Program" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
C:\Program Files (x86)\CODEBL~1\MinGW\bin\windres.exe: preprocessing failed.
Comment 9 gusfl 2015-03-15 12:03:22 UTC
windres -I "C:\Program Files\MinGW\include" "manifest.rc" manifest.o

-> "Files\MinGW\include" : directory not found