Accept trailing slashes in lstat() implementation.

lstat() is sometimes invoked with a path that ends in a slash (in
particular, when dealing with subprojects). Windows's stat() does not
accept such paths and fails with ENOENT. In this case we try again
with a cleaned-up path.
This commit is contained in:
Johannes Sixt
2007-05-24 22:26:41 +02:00
parent dafd0c5fec
commit afd5e6acb2

View File

@@ -25,7 +25,27 @@ int fchmod(int fildes, mode_t mode)
int lstat(const char *file_name, struct stat *buf)
{
return stat(file_name, buf);
int namelen;
static char alt_name[PATH_MAX];
if (!stat(file_name, buf))
return 0;
/* if file_name ended in a '/', Windows returned ENOENT;
* try again without trailing slashes
*/
if (errno != ENOENT)
return -1;
namelen = strlen(file_name);
if (namelen && file_name[namelen-1] != '/')
return -1;
while (namelen && file_name[namelen-1] == '/')
--namelen;
if (!namelen || namelen >= PATH_MAX)
return -1;
memcpy(alt_name, file_name, namelen);
alt_name[namelen] = 0;
return stat(alt_name, buf);
}
/* missing: link, mkstemp, fchmod, getuid (?), gettimeofday */