Spaces in posix paths

This is a discussion on Spaces in posix paths within the Linux Programming forums, part of the Platform Specific Boards category; How do you deal with spaces when making a valid posix path? I'm using a library that converts spaces to ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    399

    Spaces in posix paths

    How do you deal with spaces when making a valid posix path? I'm using a library that converts spaces to %20, but using %20 doesn't seem to work with any standard posix functions that deals with files.

    The library is Apple's CoreFoundation, and the function that returns the posix path with spaces encoded as %20 is CFStringGetFileSystemRepresentation.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    POSIX filenames can contain spaces. In fact, a posix filename can contain any character except / and NULL. However, you will probably not see them with *, etc, because there are some characters the shell makes impossible.

    %20 plain and simple is for use in http query strings. It has nothing to do with POSIX -- perhaps the library is presuming that this is for network transmission?

    It's probably not uncommon to set more strict rules tho, eg:
    Quote Originally Posted by University of Albany
    Filenames on Our UNIX System
    Special characters that should not be used in filenames: — & ; * ? ' " ` [ | ] ( ) $ < > { } ^ # / \ % ! ~ and the SPACE character
    Should not is not cannot, ie, this has nothing to do with "the standard".

    You might as well just replace spaces with underscores to be safe. I despise spaces in filenames because they can be a pain and require extra quoting in scripts, on the command-line, etc.
    Last edited by MK27; 12-11-2009 at 07:29 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Either way, I fixed it by replacing CFURLCopyPath with CFURLCopyFileSystemPath. So it wasn't CFStringGetFileSystemRepresentation that was doing something strange after all ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII File Copy Problem: Expand tabs to multiple spaces
    By matrixx333 in forum C Programming
    Replies: 5
    Last Post: 10-21-2009, 04:13 AM
  2. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  3. saving a CString to binary file with trailing spaces
    By nineofhearts in forum C++ Programming
    Replies: 12
    Last Post: 01-03-2006, 11:53 AM
  4. Handling spaces in command line arguments
    By starkhorn in forum C++ Programming
    Replies: 7
    Last Post: 11-16-2004, 02:42 PM
  5. Replies: 5
    Last Post: 06-30-2003, 01:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21