changeset 13696:bfe487360d66

fdutimens, fdutimensat: update signature, again In general, merging: f<act>(fd,args) and <act>at(dir,name,args) should produce: fd<act>at(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 <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Fri, 17 Sep 2010 15:08:29 -0600
parents 8a06cdf65b57
children b661c266dee7
files ChangeLog NEWS lib/fdutimensat.c lib/futimens.c lib/utimens.c lib/utimens.h tests/test-fdutimensat.c tests/test-futimens.h tests/test-utimens.c
diffstat 9 files changed, 49 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-09-17  Eric Blake  <eblake@redhat.com>
+
+	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  <bruno@clisp.org>
 
 	Take over the maintenance of some older macros from Autoconf.
--- a/NEWS
+++ b/NEWS
@@ -12,8 +12,15 @@
 
 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
--- 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;
--- a/lib/futimens.c
+++ b/lib/futimens.c
@@ -33,5 +33,5 @@
   /* 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);
 }
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -164,7 +164,7 @@
    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 @@
   }
 }
 
-/* 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 @@
 
   /* 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 @@
   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;
 }
--- a/lib/utimens.h
+++ b/lib/utimens.h
@@ -1,6 +1,5 @@
 #include <time.h>
-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 @@
 # include <fcntl.h>
 # include <sys/stat.h>
 
-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
--- a/tests/test-fdutimensat.c
+++ b/tests/test-fdutimensat.c
@@ -40,7 +40,7 @@
 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 @@
   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 @@
 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 @@
   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 @@
   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.  */
--- 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.  */
--- 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 @@
   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;