X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fstat.c;h=1fc633eeef035cf6af3c4e0994a1e5f9dc01ed6e;hb=67574205b8050b3b25de4fc8009dc61306329f6b;hp=8aa770940702e50fd81cbc0fd52e640247a32e8e;hpb=c7e61475680fa226bd9b8bdd469cd66914e630f5;p=debian%2Fgzip diff --git a/lib/stat.c b/lib/stat.c index 8aa7709..1fc633e 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -1,5 +1,5 @@ /* Work around platform bugs in stat. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,14 +16,31 @@ /* written by Eric Blake */ +/* If the user's config.h happens to include , let it include only + the system's here, so that orig_stat doesn't recurse to + rpl_stat. */ +#define __need_system_sys_stat_h #include /* Get the original definition of stat. It might be defined as a macro. */ -#define __need_system_sys_stat_h #include #include #undef __need_system_sys_stat_h +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# if _GL_WINDOWS_64_BIT_ST_SIZE +# define stat _stati64 +# define REPLACE_FUNC_STAT_DIR 1 +# undef REPLACE_FUNC_STAT_FILE +# elif REPLACE_FUNC_STAT_FILE +/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a. + Bypass it. */ +# define stat _stat +# define REPLACE_FUNC_STAT_DIR 1 +# undef REPLACE_FUNC_STAT_FILE +# endif +#endif + static inline int orig_stat (const char *filename, struct stat *buf) { @@ -31,12 +48,26 @@ orig_stat (const char *filename, struct stat *buf) } /* Specification. */ -#include +/* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc + eliminates this include because of the preliminary #include + above. */ +#include "sys/stat.h" #include #include #include #include +#include "dosname.h" +#include "verify.h" + +#if REPLACE_FUNC_STAT_DIR +# include "pathmax.h" + /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also + have a constant PATH_MAX. */ +# ifndef PATH_MAX +# error "Please port this replacement to your platform" +# endif +#endif /* Store information about NAME into ST. Work around bugs with trailing slashes. Mingw has other bugs (such as st_ino always @@ -55,13 +86,14 @@ rpl_stat (char const *name, struct stat *st) { size_t len = strlen (name); if (ISSLASH (name[len - 1])) - { - errno = ENOTDIR; - return -1; - } + { + errno = ENOTDIR; + return -1; + } } #endif /* REPLACE_FUNC_STAT_FILE */ #if REPLACE_FUNC_STAT_DIR + if (result == -1 && errno == ENOENT) { /* Due to mingw's oddities, there are some directories (like @@ -76,6 +108,7 @@ rpl_stat (char const *name, struct stat *st) char fixed_name[PATH_MAX + 1] = {0}; size_t len = strlen (name); bool check_dir = false; + verify (PATH_MAX <= 4096); if (PATH_MAX <= len) errno = ENAMETOOLONG; else if (len)