cygpath bug?

BB canofspam@att.net
Thu Jun 12 20:21:00 GMT 2003


I'm trying to use cygpath to convert a windows path with
long directory and filenames to a unix style path with only
short directory and filenames.

dos_pathname=cygpath -d "$1"
# check for errors
unix_pathname=cygpath -u "$dos_pathname"
# check for errors

I expected cygpath to return non-zero if the input path is invalid, but it
doesn't.

$ cygpath -d "c:\doesnt exist"
?

After looking at the code for cygpath, it looks like functions that call the
windows api functions GetLongPathName() and GetShortPathName() only
return an error if the functions return 0 length and GetLastError() =
ERROR_INVALID_PARAMETER  Both of these functions can return 0
length for other reasons such as an invlalid directory or filename.

As you can see in the code below, if GetShortPathName() returns 0,
the function allocates 1 byte and copies unitialized data to it.

Shouldn't GetShortPathName() == 0 always cause the get_short_name()
function to fail?  There are many other calls to these two functions.

// FROM cygpath.cc
static char *
get_short_name (const char *filename)
{
  char *sbuf, buf[MAX_PATH];
  DWORD len = GetShortPathName (filename, buf, MAX_PATH);
  if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
        filename);
      exit (2);
    }
  sbuf = (char *) malloc (++len);
  if (sbuf == NULL)
    {
      fprintf (stderr, "%s: out of memory\n", prog_name);
      exit (1);
    }
  return strcpy (sbuf, buf);
}




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list