X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fstat.c;h=cbc9100fd4d6b7d47809c78a3b91f34179bc88fe;hb=5ea8bedd0c6a7a8f29dcff301d126b58cc123ea8;hp=c3400d5b25afd571017d5f58cf22659140d2c002;hpb=5794d89bd24981d2974f1504a04bf09b7efaf251;p=gnulib.git diff --git a/lib/stat.c b/lib/stat.c index c3400d5b2..cbc9100fd 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-2011 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 @@ -18,25 +18,51 @@ #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 + +static inline int +orig_stat (const char *filename, struct stat *buf) +{ + return stat (filename, buf); +} + +/* Specification. */ #include #include #include #include #include +#include "dosname.h" -#undef stat - -/* For now, mingw is the only known platform where stat(".") and - stat("./") give different results. Mingw stat has other bugs (such - as st_ino always being 0 on success) which this wrapper does not - work around. But at least this implementation provides the ability - to emulate fchdir correctly. */ +/* Store information about NAME into ST. Work around bugs with + trailing slashes. Mingw has other bugs (such as st_ino always + being 0 on success) which this wrapper does not work around. But + at least this implementation provides the ability to emulate fchdir + correctly. */ int rpl_stat (char const *name, struct stat *st) { - int result = stat (name, st); + int result = orig_stat (name, st); +#if REPLACE_FUNC_STAT_FILE + /* Solaris 9 mistakenly succeeds when given a non-directory with a + trailing slash. */ + if (result == 0 && !S_ISDIR (st->st_mode)) + { + size_t len = strlen (name); + if (ISSLASH (name[len - 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 @@ -66,7 +92,7 @@ rpl_stat (char const *name, struct stat *st) } else fixed_name[len++] = '/'; - result = stat (fixed_name, st); + result = orig_stat (fixed_name, st); if (result == 0 && check_dir && !S_ISDIR (st->st_mode)) { result = -1; @@ -74,5 +100,6 @@ rpl_stat (char const *name, struct stat *st) } } } +#endif /* REPLACE_FUNC_STAT_DIR */ return result; }