summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-04-27 16:47:14 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-04-27 16:47:14 +0000
commit64ee50fa0e4357164273c5d8b34ccde10a69d0ef (patch)
tree0fef90a4e49a9eb2caa17bd3a665fba1d71479d1
parent70697efff43ca5f2061d45a25abb839ad37fb3bf (diff)
downloadskalibs-64ee50fa0e4357164273c5d8b34ccde10a69d0ef.tar.xz
Add new sysdeps for futimens() and futimes(), adapt touch() implementation
-rwxr-xr-xconfigure2
-rw-r--r--package/deps.mak2
-rw-r--r--src/libstddjb/touch.c37
-rw-r--r--src/sysdeps/tryfutimens.c12
-rw-r--r--src/sysdeps/tryfutimes.c11
5 files changed, 63 insertions, 1 deletions
diff --git a/configure b/configure
index a638a89..2f598f7 100755
--- a/configure
+++ b/configure
@@ -491,6 +491,8 @@ EOF
choose cl strcasestr STRCASESTR 'strcasestr()'
choose cl strnlen STRNLEN 'strnlen()'
choose c uint64t UINT64T 'uint64_t'
+ choose cl futimens FUTIMENS 'futimens()'
+ choose cl futimes FUTIMES 'futimes()'
if $forcedevr ; then
echo "/dev/random detection override required, assuming it exists and is working."
diff --git a/package/deps.mak b/package/deps.mak
index 0a85989..401d9d3 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -664,7 +664,7 @@ src/libstddjb/timestamp_scan.o src/libstddjb/timestamp_scan.lo: src/libstddjb/ti
src/libstddjb/timeval_from_tain.o src/libstddjb/timeval_from_tain.lo: src/libstddjb/timeval_from_tain.c src/include/skalibs/tai.h
src/libstddjb/timeval_from_tain_relative.o src/libstddjb/timeval_from_tain_relative.lo: src/libstddjb/timeval_from_tain_relative.c src/include/skalibs/tai.h
src/libstddjb/timeval_sysclock_from_tain.o src/libstddjb/timeval_sysclock_from_tain.lo: src/libstddjb/timeval_sysclock_from_tain.c src/include/skalibs/tai.h
-src/libstddjb/touch.o src/libstddjb/touch.lo: src/libstddjb/touch.c src/include/skalibs/djbunix.h
+src/libstddjb/touch.o src/libstddjb/touch.lo: src/libstddjb/touch.c src/include/skalibs/djbunix.h src/include/skalibs/sysdeps.h
src/libstddjb/ucharn_findlen.o src/libstddjb/ucharn_findlen.lo: src/libstddjb/ucharn_findlen.c src/include/skalibs/fmtscan.h
src/libstddjb/ucharn_fmt.o src/libstddjb/ucharn_fmt.lo: src/libstddjb/ucharn_fmt.c src/include/skalibs/fmtscan.h
src/libstddjb/ucharn_fmt_little.o src/libstddjb/ucharn_fmt_little.lo: src/libstddjb/ucharn_fmt_little.c src/include/skalibs/fmtscan.h
diff --git a/src/libstddjb/touch.c b/src/libstddjb/touch.c
index 45a8d2c..dfc3525 100644
--- a/src/libstddjb/touch.c
+++ b/src/libstddjb/touch.c
@@ -1,11 +1,48 @@
/* ISC license. */
+#include <skalibs/sysdeps.h>
#include <skalibs/djbunix.h>
+#ifdef SKALIBS_HASFUTIMENS
+
+#include <time.h>
+#include <sys/stat.h>
+
+int touch (char const *file)
+{
+ register int fd = open_create(file) ;
+ if (fd < 0) return 0 ;
+ if (futimens(fd, 0) < 0) return 0 ;
+ fd_close(fd) ;
+ return 1 ;
+}
+
+#else
+#ifdef SKALIBS_HASFUTIMES
+
+#include <sys/time.h>
+
int touch (char const *file)
{
register int fd = open_create(file) ;
if (fd < 0) return 0 ;
+ if (futimes(fd, 0) < 0) return 0 ;
fd_close(fd) ;
return 1 ;
}
+
+#else
+
+#include <sys/time.h>
+
+int touch (char const *file)
+{
+ register int fd = open_create(file) ;
+ if (fd < 0) return 0 ;
+ fd_close(fd) ;
+ if (utimes(file, 0) < 0) return 0 ;
+ return 1 ;
+}
+
+#endif
+#endif
diff --git a/src/sysdeps/tryfutimens.c b/src/sysdeps/tryfutimens.c
new file mode 100644
index 0000000..809aaa5
--- /dev/null
+++ b/src/sysdeps/tryfutimens.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
+
+int main (void)
+{
+ struct timespec foo[2] = { { .tv_sec = 0, .tv_nsec = 0 }, { .tv_sec = 0, .tv_nsec = 0 } } ;
+ futimens(0, foo) ;
+ return 0 ;
+}
diff --git a/src/sysdeps/tryfutimes.c b/src/sysdeps/tryfutimes.c
new file mode 100644
index 0000000..a65ab5a
--- /dev/null
+++ b/src/sysdeps/tryfutimes.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+int main (void)
+{
+ struct timeval foo[2] = { { .tv_sec = 0, .tv_usec = 0 }, { .tv_sec = 0, .tv_usec = 0 } } ;
+ futimes(0, foo) ;
+ return 0 ;
+}