From aba351689b1b5ce068b76d112c1f4929ac26ab9c Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 8 Oct 2009 06:40:08 -0600 Subject: [PATCH] utimens: introduce fdutimens 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 --- ChangeLog | 6 ++++++ lib/utimens.c | 18 +++++++++++++++++- lib/utimens.h | 1 + tests/test-utimens.c | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 924050874..be1bac99a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-10-10 Eric Blake + 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. diff --git a/lib/utimens.c b/lib/utimens.c index b2b25d13d..9119bc430 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -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 diff --git a/lib/utimens.h b/lib/utimens.h index 8b3ccef5e..a02c6a465 100644 --- a/lib/utimens.h +++ b/lib/utimens.h @@ -1,4 +1,5 @@ #include +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]); diff --git a/tests/test-utimens.c b/tests/test-utimens.c index 0b00fadb4..e43663a12 100644 --- a/tests/test-utimens.c +++ b/tests/test-utimens.c @@ -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; -- 2.11.0