summaryrefslogtreecommitdiff
path: root/lib/fstatat.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-11-23 00:05:57 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-11-23 00:06:42 -0800
commit2c5d5587453d18cf83bdf67b4914db5e5db684b1 (patch)
treeb2b1f2682c97bc7a9087651aee6f3a9db05fe9e9 /lib/fstatat.c
parent6245cd45374f0db1e832ed81b1b7c60ef8f5784f (diff)
downloadgnulib-2c5d5587453d18cf83bdf67b4914db5e5db684b1.tar.gz
stat: work around Solaris bug with tv_nsec < 0
* doc/posix-functions/fstat.texi (fstat): * doc/posix-functions/fstatat.texi (fstatat): * doc/posix-functions/lstat.texi (lstat): * doc/posix-functions/stat.texi (stat): Mention Solaris 11 bug. * lib/fstat.c, lib/fstatat.c, lib/lstat.c: Include stat-time.h. * lib/fstat.c (rpl_fstat) [!WINDOWS_NATIVE]: * lib/lstat.c (rpl_lstat): * lib/stat.c (rpl_stat): Normalize resulting timestamps. * lib/fstatat.c (normal_fstatat): New function. (rpl_fstatat): Use it. * lib/stat-time.h: Include intprops.h, errno.h, stddef.h. (stat_time_normalize): New function. * m4/fstat.m4 (gl_FUNC_FSTAT): * m4/fstatat.m4 (gl_FUNC_FSTATAT): * m4/lstat.m4 (gl_FUNC_LSTAT): * m4/stat.m4 (gl_FUNC_STAT): Replace on Solaris. * modules/fstat (Depends-on): * modules/fstatat (Depends-on): Add stat-time. * modules/stat-time (Depends-on): Add errno, intprops.
Diffstat (limited to 'lib/fstatat.c')
-rw-r--r--lib/fstatat.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/fstatat.c b/lib/fstatat.c
index 294861f51b..237e68c5da 100644
--- a/lib/fstatat.c
+++ b/lib/fstatat.c
@@ -41,6 +41,8 @@ orig_fstatat (int fd, char const *filename, struct stat *buf, int flags)
above. */
#include "sys/stat.h"
+#include "stat-time.h"
+
#include <errno.h>
#include <fcntl.h>
#include <string.h>
@@ -51,6 +53,12 @@ orig_fstatat (int fd, char const *filename, struct stat *buf, int flags)
# define LSTAT_FOLLOWS_SLASHED_SYMLINK 0
# endif
+static int
+normal_fstatat (int fd, char const *file, struct stat *st, int flag)
+{
+ return stat_time_normalize (orig_fstatat (fd, file, st, flag), st);
+}
+
/* fstatat should always follow symbolic links that end in /, but on
Solaris 9 it doesn't if AT_SYMLINK_NOFOLLOW is specified.
Likewise, trailing slash on a non-directory should be an error.
@@ -63,7 +71,7 @@ orig_fstatat (int fd, char const *filename, struct stat *buf, int flags)
int
rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
{
- int result = orig_fstatat (fd, file, st, flag);
+ int result = normal_fstatat (fd, file, st, flag);
size_t len;
if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0)
@@ -79,7 +87,7 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
errno = ENOTDIR;
return -1;
}
- result = orig_fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW);
+ result = normal_fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW);
}
/* Fix stat behavior. */
if (result == 0 && !S_ISDIR (st->st_mode) && file[len - 1] == '/')