Thread: More canonicalization fixes

More canonicalization fixes

From
Bruce Momjian
Date:
I just applied this new version of canonicalize_path():

    /*
     * Make all paths look like Unix
     */
    void
    canonicalize_path(char *path)
    {
    #ifdef WIN32
        /*
         * The Windows command processor will accept suitably quoted paths
         * with forward slashes, but barfs badly with mixed forward and back
         * slashes.
         */
        char       *p;

        for (p = path; *p; p++)
        {
            if (*p == '\\')
                *p = '/';
        }

        /*  In Win32, if you do:
         *      prog.exe "a b" "\c\d\"
         *  the system will pass \c\d" as argv[2].
         */
        if (p > path && *(p-1) == '"')
            *(p-1) = '/';
    #endif

        /*
         *  Removing the trailing slash on a path means we never get
         *  ugly double slashes.  Don't remove a leading slash, though.
         *  Also, Win32 can't stat() a directory with a trailing slash.
         */
        trim_trailing_separator(path);
    }

The new thing Magnus found was this in Win32:

    prog.exe "a b" "\c\d\"

returns \c\d" as argv[2]

Quite amazing. The fix on Win32 is to convert a trailing double-quote to
a slash.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073