delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/06/12/16:21:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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" <canofspam AT att DOT net>
Subject: cygpath bug?
Date: Thu, 12 Jun 2003 15:20:58 -0500
Lines: 49
Message-ID: <bcan6d$67i$1@main.gmane.org>
Reply-To: "BB" <canofspam AT att DOT net>
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019