bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fdutimens, fdutimensat: update signature, again


From: Eric Blake
Subject: [PATCH] fdutimens, fdutimensat: update signature, again
Date: Fri, 17 Sep 2010 15:11:33 -0600

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 <address@hidden>
---

Done.

 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 2356ea5..6c46a5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-09-17  Eric Blake  <address@hidden>
+
+       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  <address@hidden>

        Take over the maintenance of some older macros from Autoconf.
diff --git a/NEWS b/NEWS
index 7d01eef..377898d 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 0219a78..6766b93 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 ff7c7b4..f5f4d74 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 35d082d..088c4ba 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 f651bee..8c47cf9 100644
--- 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 @@ int lutimens (char const *, struct timespec const [2]);
 # 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
diff --git a/tests/test-fdutimensat.c b/tests/test-fdutimensat.c
index 80eb373..d94667a 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 97c7acd..ab86ae2 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 f2a31a8..09c353b 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;
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]