Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Injected-Via-Gmane: http://gmane.org/ To: cygwin AT cygwin DOT com From: "BB" Subject: cygpath bug? Date: Thu, 12 Jun 2003 15:20:58 -0500 Lines: 49 Message-ID: Reply-To: "BB" X-Complaints-To: usenet AT main DOT gmane DOT org X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 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/