From 89b0db35db10a8beccaf83909c7f62f127fb5821 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 17 Sep 2010 15:08:29 -0600 Subject: [PATCH] fdutimens, fdutimensat: update signature, again In general, merging: f(fd,args) and at(dir,name,args) should produce: fdat(fd,dir,name,args) * lib/utimens.h (gl_futimens): Delete, and move signature... (fdutimens): ...here. (fdutimensat): Rearrange signature. (lutimensat): Rename variable for clarity. * lib/fdutimensat.c (fdutimensat): Update signature. * lib/utimens.c (fdutimens): Likewise. (gl_futimens): Delete. (utimens, lutimens): Update callers. * lib/futimens.c (futimens): Likewise. * tests/test-fdutimensat.c: Likewise. * tests/test-utimens.c: Likewise. * tests/test-futimens.h: Update comment. * NEWS: Mention this. Suggested by Paul Eggert. Signed-off-by: Eric Blake --- ChangeLog | 18 ++++++++++++++++++ NEWS | 11 +++++++++-- lib/fdutimensat.c | 2 +- lib/futimens.c | 2 +- lib/utimens.c | 24 ++++-------------------- lib/utimens.h | 9 ++++----- tests/test-fdutimensat.c | 16 ++++++++-------- tests/test-futimens.h | 2 +- tests/test-utimens.c | 6 +++--- 9 files changed, 49 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2356ea56e..6c46a5b8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2010-09-17 Eric Blake + + fdutimens, fdutimensat: update signature, again + * lib/utimens.h (gl_futimens): Delete, and move signature... + (fdutimens): ...here. + (fdutimensat): Rearrange signature. + (lutimensat): Rename variable for clarity. + * lib/fdutimensat.c (fdutimensat): Update signature. + * lib/utimens.c (fdutimens): Likewise. + (gl_futimens): Delete. + (utimens, lutimens): Update callers. + * lib/futimens.c (futimens): Likewise. + * tests/test-fdutimensat.c: Likewise. + * tests/test-utimens.c: Likewise. + * tests/test-futimens.h: Update comment. + * NEWS: Mention this. + Suggested by Paul Eggert. + 2010-09-17 Bruno Haible Take over the maintenance of some older macros from Autoconf. diff --git a/NEWS b/NEWS index 7d01eef3a..377898dcb 100644 --- a/NEWS +++ b/NEWS @@ -12,8 +12,15 @@ User visible incompatible changes Date Modules Changes -2010-09-16 fdutimensat The function now takes a new parameter; old users - can safely pass atflag=0 for no semantic change. +2010-09-17 utimens The function gl_futimens is removed, and its + signature has been migrated to fdutimens. Callers + of gl_futimens should change function name, and + callers of fdutimens should swap parameter order. + +2010-09-17 fdutimensat This function has a new signature: the fd now comes + first instead of the dir/name pair, and a new + atflag parameter is added at the end. Old code + should rearrange parameters, and pass 0 for atflag. 2010-09-13 regex The module is not guaranteeing anymore support for 64-bit regoff_t on 64-bit systems. The size of diff --git a/lib/fdutimensat.c b/lib/fdutimensat.c index 0219a7832..6766b931f 100644 --- a/lib/fdutimensat.c +++ b/lib/fdutimensat.c @@ -40,7 +40,7 @@ Return 0 on success, -1 (setting errno) on failure. */ int -fdutimensat (int dir, char const *file, int fd, struct timespec const ts[2], +fdutimensat (int fd, int dir, char const *file, struct timespec const ts[2], int atflag) { int result = 1; diff --git a/lib/futimens.c b/lib/futimens.c index ff7c7b4d3..f5f4d7497 100644 --- a/lib/futimens.c +++ b/lib/futimens.c @@ -33,5 +33,5 @@ futimens (int fd, struct timespec const times[2]) /* fdutimens also works around bugs in native futimens, when running with glibc compiled against newer headers but on a Linux kernel older than 2.6.32. */ - return fdutimens (NULL, fd, times); + return fdutimens (fd, NULL, times); } diff --git a/lib/utimens.c b/lib/utimens.c index 35d082de5..088c4baa7 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -164,7 +164,7 @@ update_timespec (struct stat const *statbuf, struct timespec *ts[2]) Return 0 on success, -1 (setting errno) on failure. */ int -fdutimens (char const *file, int fd, struct timespec const timespec[2]) +fdutimens (int fd, char const *file, struct timespec const timespec[2]) { struct timespec adjusted_timespec[2]; struct timespec *ts = timespec ? adjusted_timespec : NULL; @@ -370,28 +370,12 @@ fdutimens (char const *file, int fd, struct timespec const timespec[2]) } } -/* Set the access and modification time stamps of FD (a.k.a. FILE) to be - TIMESPEC[0] and TIMESPEC[1], respectively. - FD must be either negative -- in which case it is ignored -- - or a file descriptor that is open on FILE. - If FD is nonnegative, then FILE can be NULL, which means - use just futimes (or equivalent) instead of utimes (or equivalent), - and fail if on an old system without futimes (or equivalent). - If TIMESPEC is null, set the time stamps to the current time. - Return 0 on success, -1 (setting errno) on failure. */ - -int -gl_futimens (int fd, char const *file, struct timespec const timespec[2]) -{ - return fdutimens (file, fd, timespec); -} - /* Set the access and modification time stamps of FILE to be TIMESPEC[0] and TIMESPEC[1], respectively. */ int utimens (char const *file, struct timespec const timespec[2]) { - return fdutimens (file, -1, timespec); + return fdutimens (-1, file, timespec); } /* Set the access and modification time stamps of FILE to be @@ -417,7 +401,7 @@ lutimens (char const *file, struct timespec const timespec[2]) /* The Linux kernel did not support symlink timestamps until utimensat, in version 2.6.22, so we don't need to mimic - gl_futimens' worry about buggy NFS clients. But we do have to + fdutimens' worry about buggy NFS clients. But we do have to worry about bogus return values. */ #if HAVE_UTIMENSAT @@ -507,7 +491,7 @@ lutimens (char const *file, struct timespec const timespec[2]) if (!(adjustment_needed || REPLACE_FUNC_STAT_FILE) && lstat (file, &st)) return -1; if (!S_ISLNK (st.st_mode)) - return fdutimens (file, -1, ts); + return fdutimens (-1, file, ts); errno = ENOSYS; return -1; } diff --git a/lib/utimens.h b/lib/utimens.h index f651beeba..8c47cf93f 100644 --- a/lib/utimens.h +++ b/lib/utimens.h @@ -1,6 +1,5 @@ #include -int fdutimens (char const *, int, struct timespec const [2]); -int gl_futimens (int, char const *, struct timespec const [2]); +int fdutimens (int, char const *, struct timespec const [2]); int utimens (char const *, struct timespec const [2]); int lutimens (char const *, struct timespec const [2]); @@ -8,13 +7,13 @@ int lutimens (char const *, struct timespec const [2]); # include # include -int fdutimensat (int dir, char const *name, int fd, struct timespec const [2], +int fdutimensat (int fd, int dir, char const *name, struct timespec const [2], int atflag); /* Using this function makes application code slightly more readable. */ static inline int -lutimensat (int fd, char const *file, struct timespec const times[2]) +lutimensat (int dir, char const *file, struct timespec const times[2]) { - return utimensat (fd, file, times, AT_SYMLINK_NOFOLLOW); + return utimensat (dir, file, times, AT_SYMLINK_NOFOLLOW); } #endif diff --git a/tests/test-fdutimensat.c b/tests/test-fdutimensat.c index 80eb373d0..d94667af9 100644 --- a/tests/test-fdutimensat.c +++ b/tests/test-fdutimensat.c @@ -40,7 +40,7 @@ static int dfd = AT_FDCWD; static int do_futimens (int fd, struct timespec const times[2]) { - return fdutimensat (dfd, NULL, fd, times, 0); + return fdutimensat (fd, dfd, NULL, times, 0); } /* Test the use of file descriptors alongside a name. */ @@ -52,8 +52,8 @@ do_fdutimens (char const *name, struct timespec const times[2]) if (fd < 0) fd = openat (dfd, name, O_RDONLY); errno = 0; - result = fdutimensat (dfd, name, fd, times, 0); - ASSERT (fdutimensat (dfd, name, fd, times, AT_SYMLINK_NOFOLLOW) == result); + result = fdutimensat (fd, dfd, name, times, 0); + ASSERT (fdutimensat (fd, dfd, name, times, AT_SYMLINK_NOFOLLOW) == result); if (0 <= fd) { int saved_errno = errno; @@ -74,14 +74,14 @@ do_lutimens (const char *name, struct timespec const times[2]) static int do_lutimens1 (const char *name, struct timespec const times[2]) { - return fdutimensat (dfd, name, -1, times, AT_SYMLINK_NOFOLLOW); + return fdutimensat (-1, dfd, name, times, AT_SYMLINK_NOFOLLOW); } /* Wrap fdutimensat to behave like utimens. */ static int do_utimens (const char *name, struct timespec const times[2]) { - return fdutimensat (dfd, name, -1, times, 0); + return fdutimensat (-1, dfd, name, times, 0); } int @@ -117,12 +117,12 @@ main (void) fd = creat ("file", 0600); ASSERT (0 <= fd); errno = 0; - ASSERT (fdutimensat (fd, ".", AT_FDCWD, NULL, 0) == -1); + ASSERT (fdutimensat (AT_FDCWD, fd, ".", NULL, 0) == -1); ASSERT (errno == ENOTDIR); { struct timespec ts[2] = { { Y2K, 0 }, { Y2K, 0 } }; struct stat st; - ASSERT (fdutimensat (dfd, BASE "dir/file", fd, ts, 0) == 0); + ASSERT (fdutimensat (fd, dfd, BASE "dir/file", ts, 0) == 0); ASSERT (stat ("file", &st) == 0); ASSERT (st.st_atime == Y2K); ASSERT (get_stat_atime_ns (&st) == 0); @@ -132,7 +132,7 @@ main (void) ASSERT (close (fd) == 0); ASSERT (close (dfd) == 0); errno = 0; - ASSERT (fdutimensat (dfd, ".", -1, NULL, 0) == -1); + ASSERT (fdutimensat (-1, dfd, ".", NULL, 0) == -1); ASSERT (errno == EBADF); /* Cleanup. */ diff --git a/tests/test-futimens.h b/tests/test-futimens.h index 97c7acddc..ab86ae217 100644 --- a/tests/test-futimens.h +++ b/tests/test-futimens.h @@ -16,7 +16,7 @@ #include "test-utimens-common.h" -/* This file is designed to test both gl_futimens(a,NULL,b) and +/* This file is designed to test both fdutimens(a,NULL,b) and futimens(a,b). FUNC is the function to test. Assumes that BASE and ASSERT are already defined. If PRINT, warn before skipping tests with status 77. */ diff --git a/tests/test-utimens.c b/tests/test-utimens.c index f2a31a88e..09c353b01 100644 --- a/tests/test-utimens.c +++ b/tests/test-utimens.c @@ -33,11 +33,11 @@ #include "test-lutimens.h" #include "test-utimens.h" -/* Wrap gl_futimens to behave like futimens. */ +/* Wrap fdutimens to behave like futimens. */ static int do_futimens (int fd, struct timespec const times[2]) { - return gl_futimens (fd, NULL, times); + return fdutimens (fd, NULL, times); } /* Test the use of file descriptors alongside a name. */ @@ -49,7 +49,7 @@ do_fdutimens (char const *name, struct timespec const times[2]) if (fd < 0) fd = open (name, O_RDONLY); errno = 0; - result = fdutimens (name, fd, times); + result = fdutimens (fd, name, times); if (0 <= fd) { int saved_errno = errno; -- 2.11.0