diff options
author | Li Jinjing <jinjingx.li@intel.com> | 2014-10-26 22:28:15 +0800 |
---|---|---|
committer | Li Jinjing <jinjingx.li@intel.com> | 2014-10-26 22:28:15 +0800 |
commit | 931b01b091932a1f796c23379ea32abb68bd5895 (patch) | |
tree | 3aa9e1125da84f7e3bd764bbff577c42a766508b /lib/stat.c | |
parent | 7be93f2d05131d061bd4790ae33c8d50f50010d7 (diff) | |
download | m4-931b01b091932a1f796c23379ea32abb68bd5895.tar.gz m4-931b01b091932a1f796c23379ea32abb68bd5895.tar.bz2 m4-931b01b091932a1f796c23379ea32abb68bd5895.zip |
Imported Upstream version 1.4.17upstream/1.4.17sandbox/jinjingx/upstream
Diffstat (limited to 'lib/stat.c')
-rw-r--r-- | lib/stat.c | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -1,5 +1,5 @@ /* Work around platform bugs in stat. - Copyright (C) 2009-2011 Free Software Foundation, Inc. + Copyright (C) 2009-2013 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,28 +16,59 @@ /* written by Eric Blake */ +/* If the user's config.h happens to include <sys/stat.h>, let it include only + the system's <sys/stat.h> here, so that orig_stat doesn't recurse to + rpl_stat. */ +#define __need_system_sys_stat_h #include <config.h> /* Get the original definition of stat. It might be defined as a macro. */ -#define __need_system_sys_stat_h #include <sys/types.h> #include <sys/stat.h> #undef __need_system_sys_stat_h -static inline int +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# if _GL_WINDOWS_64_BIT_ST_SIZE +# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ +# 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 int orig_stat (const char *filename, struct stat *buf) { return stat (filename, buf); } /* Specification. */ -#include <sys/stat.h> +/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc + eliminates this include because of the preliminary #include <sys/stat.h> + above. */ +#include "sys/stat.h" #include <errno.h> #include <limits.h> #include <stdbool.h> #include <string.h> #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 @@ -63,6 +94,7 @@ rpl_stat (char const *name, struct stat *st) } #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 @@ -77,6 +109,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) |