utimens: introduce fdutimens
authorEric Blake <ebb9@byu.net>
Thu, 8 Oct 2009 12:40:08 +0000 (06:40 -0600)
committerEric Blake <ebb9@byu.net>
Sat, 10 Oct 2009 14:51:22 +0000 (08:51 -0600)
at-func.c wants the file name argument first.  This also paves the
way to add fdutimensat(dfd,name,fd,times,flag).

* lib/utimens.h (fdutimens): New prototype.
* lib/utimens.c (gl_futimens): Move guts...
(fdutimens): ...to new interface.
* tests/test-utimens.c (do_fdutimens): Use it.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/utimens.c
lib/utimens.h
tests/test-utimens.c

index 9240508..be1bac9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-10-10  Eric Blake  <ebb9@byu.net>
 
+       utimens: introduce fdutimens
+       * lib/utimens.h (fdutimens): New prototype.
+       * lib/utimens.c (gl_futimens): Move guts...
+       (fdutimens): ...to new interface.
+       * tests/test-utimens.c (do_fdutimens): Use it.
+
        utimens: add UTIME_NOW and UTIME_OMIT support
        * lib/utimens.c (validate_timespec, update_timespec): New helper
        functions.
index b2b25d1..9119bc4 100644 (file)
@@ -132,7 +132,7 @@ update_timespec (struct stat const *statbuf, struct timespec *ts[2])
    Return 0 on success, -1 (setting errno) on failure.  */
 
 int
-gl_futimens (int fd, char const *file, struct timespec const timespec[2])
+fdutimens (char const *file, int fd, struct timespec const timespec[2])
 {
   struct timespec adjusted_timespec[2];
   struct timespec *ts = timespec ? adjusted_timespec : NULL;
@@ -300,6 +300,22 @@ gl_futimens (int fd, char const *file, 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
index 8b3ccef..a02c6a4 100644 (file)
@@ -1,4 +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 utimens (char const *, struct timespec const [2]);
 int lutimens (char const *, struct timespec const [2]);
index 0b00fad..e43663a 100644 (file)
@@ -58,7 +58,7 @@ do_fdutimens (char const *name, struct timespec const times[2])
   if (fd < 0)
     fd = open (name, O_RDONLY);
   errno = 0;
-  result = gl_futimens (fd, name, times);
+  result = fdutimens (name, fd, times);
   if (0 <= fd)
     {
       int saved_errno = errno;