Mercurial > hg > octave-kai > gnulib-hg
changeset 12162:fe82ecf4f214
futimens: new module
Provides futimens where it is missing, and rpl_futimens to work
around bugs in older Linux kernels.
* modules/futimens: New file.
* lib/futimens.c (futimens): Likewise.
* m4/futimens.m4 (gl_FUNC_FUTIMENS): Likewise.
* lib/utimens.c (futimens): Avoid recursion into rpl_futimens, so
we can work around Linux bugs.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Add witnesses.
* modules/sys_stat (Makefile.am): Substitute them.
* lib/sys_stat.in.h (futimens): Declare it.
* MODULES.html.sh (systems lacking POSIX:2008): Mention module.
* doc/posix-functions/futimens.texi (futimens): Likewise.
* modules/futimens-tests: New test.
* tests/test-futimens.c: Likewise.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Fri, 09 Oct 2009 16:05:19 -0600 |
parents | c4a167621772 |
children | e16b6783660e |
files | ChangeLog MODULES.html.sh doc/posix-functions/futimens.texi lib/futimens.c lib/sys_stat.in.h lib/utimens.c m4/futimens.m4 m4/sys_stat_h.m4 modules/futimens modules/futimens-tests modules/sys_stat tests/test-futimens.c |
diffstat | 12 files changed, 228 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2009-10-10 Eric Blake <ebb9@byu.net> + futimens: new module + * modules/futimens: New file. + * lib/futimens.c (futimens): Likewise. + * m4/futimens.m4 (gl_FUNC_FUTIMENS): Likewise. + * lib/utimens.c (futimens): Avoid recursion into rpl_futimens, so + we can work around Linux bugs. + * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Add witnesses. + * modules/sys_stat (Makefile.am): Substitute them. + * lib/sys_stat.in.h (futimens): Declare it. + * MODULES.html.sh (systems lacking POSIX:2008): Mention module. + * doc/posix-functions/futimens.texi (futimens): Likewise. + * modules/futimens-tests: New test. + * tests/test-futimens.c: Likewise. + utimens: introduce fdutimens * lib/utimens.h (fdutimens): New prototype. * lib/utimens.c (gl_futimens): Move guts...
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2262,6 +2262,7 @@ func_module ftell func_module ftello func_module ftruncate + func_module futimens func_module getaddrinfo func_module getcwd func_module getgroups
--- a/doc/posix-functions/futimens.texi +++ b/doc/posix-functions/futimens.texi @@ -4,14 +4,10 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/futimens.html} -Gnulib module: --- +Gnulib module: futimens Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: glibc 2.3.6, MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX @@ -26,9 +22,12 @@ the @code{tv_sec} argument to be 0, and don't necessarily handle all file permissions in the manner required by POSIX: Linux kernel 2.6.25. +@end itemize + +Portability problems not fixed by Gnulib: +@itemize @item Some platforms lack the ability to change the timestamps of a file -descriptor, so this function can fail with @code{ENOSYS}. +descriptor, so the replacement can fail with @code{ENOSYS}; the gnulib +module @samp{utimens} provides a more reliable interface @code{gl_futimens}. @end itemize - -The gnulib module utimens provides a similar interface.
new file mode 100644 --- /dev/null +++ b/lib/futimens.c @@ -0,0 +1,37 @@ +/* Set the access and modification time of an open fd. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* written by Eric Blake */ + +#include <config.h> + +#include <sys/stat.h> + +#include "utimens.h" + +/* Set the access and modification time stamps of FD to be + TIMESPEC[0] and TIMESPEC[1], respectively. + Fail with ENOSYS on systems without futimes (or equivalent). + If TIMESPEC is null, set theh time stamps to the current time. + Return 0 on success, -1 (setting errno) on failure. */ +int +futimens (int fd, const struct timespec 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.26. */ + return fdutimens (NULL, fd, times); +}
--- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -355,6 +355,23 @@ #endif +#if @GNULIB_FUTIMENS@ +# if @REPLACE_FUTIMENS@ +# undef futimens +# define futimens rpl_futimens +# endif +# if !@HAVE_FUTIMENS@ || @REPLACE_FUTIMENS@ +extern int futimens (int fd, struct timespec const times[2]); +# endif +#elif defined GNULIB_POSIXCHECK +# undef futimens +# define futimens(f,t) \ + (GL_LINK_WARNING ("futimens is not portable - " \ + "use gnulib module futimens for portability"), \ + futimens (f, t)) +#endif + + #if @GNULIB_MKDIRAT@ # if !@HAVE_MKDIRAT@ extern int mkdirat (int fd, char const *file, mode_t mode);
--- a/lib/utimens.c +++ b/lib/utimens.c @@ -49,6 +49,9 @@ }; #endif +/* Avoid recursion with rpl_futimens. */ +#undef futimens + /* Validate the requested timestamps. Return 0 if the resulting timespec can be used for utimensat (after possibly modifying it to work around bugs in utimensat). Return 1 if the timespec needs
new file mode 100644 --- /dev/null +++ b/m4/futimens.m4 @@ -0,0 +1,41 @@ +# serial 1 +# See if we need to provide futimens replacement. + +dnl Copyright (C) 2009 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Written by Eric Blake. + +AC_DEFUN([gl_FUNC_FUTIMENS], +[ + AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_CHECK_FUNCS_ONCE([futimens]) + if test $ac_cv_func_futimens = no; then + HAVE_FUTIMENS=0 + AC_LIBOBJ([futimens]) + else + AC_CACHE_CHECK([whether futimens works], + [gl_cv_func_futimens_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include <fcntl.h> +#include <sys/stat.h> +#ifdef __linux__ +/* The Linux kernel added futimens in 2.6.22, but it had bugs until 2.6.26. + Always replace futimens to support older kernels. */ +choke me +#endif +]], [[struct timespec ts[2] = { { 1, UTIME_OMIT }, { 1, UTIME_OMIT } }; + if (futimens (AT_FDCWD, NULL)) return 1; + return futimens (open (".", O_RDONLY), ts);]])], + [gl_cv_func_futimens_works=yes], + [gl_cv_func_futimens_works="needs runtime check"], + [gl_cv_func_futimens_works="guessing no"])]) + if test "$gl_cv_func_futimens_works" != yes; then + REPLACE_FUTIMENS=1 + AC_LIBOBJ([futimens]) + fi + fi +])
--- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -1,4 +1,4 @@ -# sys_stat_h.m4 serial 17 -*- Autoconf -*- +# sys_stat_h.m4 serial 18 -*- Autoconf -*- dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -41,6 +41,7 @@ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR GNULIB_FCHMODAT=0; AC_SUBST([GNULIB_FCHMODAT]) GNULIB_FSTATAT=0; AC_SUBST([GNULIB_FSTATAT]) + GNULIB_FUTIMENS=0; AC_SUBST([GNULIB_FUTIMENS]) GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD]) GNULIB_LSTAT=0; AC_SUBST([GNULIB_LSTAT]) GNULIB_MKDIRAT=0; AC_SUBST([GNULIB_MKDIRAT]) @@ -50,6 +51,7 @@ dnl Assume proper GNU behavior unless another module says otherwise. HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT]) HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT]) + HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS]) HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD]) HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT]) HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT]) @@ -57,6 +59,7 @@ HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT]) REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT]) REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT]) + REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS]) REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT]) REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR]) REPLACE_STAT=0; AC_SUBST([REPLACE_STAT])
new file mode 100644 --- /dev/null +++ b/modules/futimens @@ -0,0 +1,28 @@ +Description: +Set file access and modification times of a file descriptor. + +Files: +lib/futimens.c +m4/futimens.m4 + +Depends-on: +sys_stat +utimens + +configure.ac: +gl_FUNC_FUTIMENS +gl_SYS_STAT_MODULE_INDICATOR([futimens]) + +Makefile.am: + +Include: +<sys/stat.h> + +Link: +$(LIB_CLOCK_GETTIME) + +License: +GPL + +Maintainer: +Eric Blake
new file mode 100644 --- /dev/null +++ b/modules/futimens-tests @@ -0,0 +1,15 @@ +Files: +tests/test-futimens.h +tests/test-futimens.c + +Depends-on: +timespec +utimecmp + +configure.ac: +AC_CHECK_FUNCS_ONCE([usleep]) + +Makefile.am: +TESTS += test-futimens +check_PROGRAMS += test-futimens +test_futimens_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) @LIBINTL@
--- a/modules/sys_stat +++ b/modules/sys_stat @@ -28,6 +28,7 @@ -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \ -e 's|@''GNULIB_FCHMODAT''@|$(GNULIB_FCHMODAT)|g' \ -e 's|@''GNULIB_FSTATAT''@|$(GNULIB_FSTATAT)|g' \ + -e 's|@''GNULIB_FUTIMENS''@|$(GNULIB_FUTIMENS)|g' \ -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \ -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \ -e 's|@''GNULIB_MKDIRAT''@|$(GNULIB_MKDIRAT)|g' \ @@ -36,6 +37,7 @@ -e 's|@''GNULIB_STAT''@|$(GNULIB_STAT)|g' \ -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \ -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \ + -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \ -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \ -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \ -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \ @@ -43,6 +45,7 @@ -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \ -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \ -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \ + -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \ -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \ -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
new file mode 100644 --- /dev/null +++ b/tests/test-futimens.c @@ -0,0 +1,58 @@ +/* Tests of futimens. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Eric Blake <ebb9@byu.net>, 2009. */ + +#include <config.h> + +#include <sys/stat.h> + +#include <fcntl.h> +#include <errno.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "stat-time.h" +#include "timespec.h" +#include "utimecmp.h" + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ + while (0) + +#define BASE "test-futimens.t" + +#include "test-futimens.h" + +int +main () +{ + /* Clean up any trash from prior testsuite runs. */ + ASSERT (system ("rm -rf " BASE "*") == 0); + + return test_futimens (futimens, true); +}