Professional Web Applications Themes

Escape characters missing from FSRefMakePath path...(?) - Mac Programming

I've encountered a strange problem with FSRefMakePath---namely, it fails to properly use escape characters. For example, I have a folder on the root drive named: Old Doents My program correctly retrieves an FSSpec to: Old Doents:olddoc.doc but when the path is created (courtesy of FSRefMakePath), it looks like this: Old Doents/olddoc.doc whereas it should be: Old\ Doents/olddoc.doc I'm using the code below. dasFile is a valid FSSpec: FSRef dasFileRef; UInt8 myPath[1024]; err = FSpMakeFSRef( &dasFile, &dasFileRef ); memset(myPath, 0, sizeof(myPath)); err = FSRefMakePath( &dasFileRef, myPath, 1024); Is this a bug or is the function just not meant for these more ...

  1. #1

    Default Escape characters missing from FSRefMakePath path...(?)

    I've encountered a strange problem with FSRefMakePath---namely, it fails to
    properly use escape characters.

    For example, I have a folder on the root drive named:
    Old Doents

    My program correctly retrieves an FSSpec to:
    Old Doents:olddoc.doc

    but when the path is created (courtesy of FSRefMakePath), it looks like
    this:

    Old Doents/olddoc.doc

    whereas it should be:
    Old\ Doents/olddoc.doc

    I'm using the code below. dasFile is a valid FSSpec:

    FSRef dasFileRef;
    UInt8 myPath[1024];
    err = FSpMakeFSRef( &dasFile, &dasFileRef );
    memset(myPath, 0, sizeof(myPath));
    err = FSRefMakePath( &dasFileRef, myPath, 1024);

    Is this a bug or is the function just not meant for these more "complex"
    situations?

    Thanks,

    Alex

    Alex Guest

  2. #2

    Default Re: Escape characters missing from FSRefMakePath path...(?)

    On Mon, 10 Nov 2003, Alex Rampell wrote:
     
    This is normal I believe. When you pass a string to an api (fopen ...) it
    knows that a space is a space and so on. The escaping is only needed when you
    type stuff into a shell, which needs to know whether you mean "foo bla"
    or "foo" "bla" as 2 separate arguments.

    AFAIK FSRefMakePath is only designed to work in the first case, not for
    generating a string that a shell will understand properly

    Fred

    Frederick Guest

  3. #3

    Default Re: Escape characters missing from FSRefMakePath path...(?)

    Hi Fred,

    Thanks---I didn't realize that.

    The reason why I am doing this is to delete a file---I want to delete an
    application before it quits, which FSpDelete won't allow, so I'm just
    calling "system("rm path/to/file)"

    Is there a more recommended way to do this? Something that does the same
    thing as rm but won't require the characters to be escaped?

    -Alex

    in article
    srcf.societies.cam.ac.uk,
    Frederick Cheung at DUH.ucam.org wrote on 11/10/03 10:40:
     
    > This is normal I believe. When you pass a string to an api (fopen ...) it
    > knows that a space is a space and so on. The escaping is only needed when you
    > type stuff into a shell, which needs to know whether you mean "foo bla"
    > or "foo" "bla" as 2 separate arguments.
    >
    > AFAIK FSRefMakePath is only designed to work in the first case, not for
    > generating a string that a shell will understand properly
    >
    > Fred
    >[/ref]



    Alex Guest

  4. #4

    Default Re: Escape characters missing from FSRefMakePath path...(?)

    On Mon, 10 Nov 2003, Alex Rampell wrote:
     

    You could call rm directly (with execve for example), or better, you
    should be able to use the function that rm will end up calling, ie unlink.

    Fred

    Frederick Guest

  5. #5

    Default Re: Escape characters missing from FSRefMakePath path...(?)

    In article <BBD51F9F.2AB02%rampellsoft.com>,
    Alex Rampell <rampellsoft.com> wrote:
     

    Remember that paths are used for a lot more than just passing to shells.
    They're passed directly as program arguments, or to functions which take
    paths. And in those cases, not only escaping unnecessary but it's wrong,
    since the escapes will be interpreted as part of the path.

    It's not 'rm' that needs escaping, it's the shell, which system calls.
    You can still use rm for this, by using a fork/exec combo instead of
    system(). Or just use the system call that rm uses, which is unlink.
    Type 'man unlink' in Terminal for more information on that.

    As a side note, this is a perfect illustration of why system() should
    pretty much never be called with anything other than a constant string.
    Michael Guest

  6. #6

    Default Re: Escape characters missing from FSRefMakePath path...(?)

    In article <BBD51F9F.2AB02%rampellsoft.com>,
    Alex Rampell <rampellsoft.com> wrote:
     

    You should never use system() for anything.

    Use unlink() to do what you are trying to do.

    Also, you should probably be moving the app to the trash, not deleting it
    outright anyway.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

Similar Threads

  1. Replies: 0
    Last Post: January 17th, 07:47 PM
  2. \' and \" (general escape characters)
    By Viruss in forum PHP Development
    Replies: 2
    Last Post: May 28th, 10:27 AM
  3. Escape regex harmful characters
    By Kevin Old in forum PERL Beginners
    Replies: 3
    Last Post: December 31st, 03:59 AM
  4. Escape characters going into MySQL
    By Geoffrey in forum FileMaker
    Replies: 4
    Last Post: November 7th, 09:07 PM
  5. Escape sequence for unicode characters in NSString
    By Eric Raas in forum Mac Programming
    Replies: 2
    Last Post: July 9th, 02:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139