diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-04-27 16:47:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-04-27 16:47:14 +0000 |
commit | 64ee50fa0e4357164273c5d8b34ccde10a69d0ef (patch) | |
tree | 0fef90a4e49a9eb2caa17bd3a665fba1d71479d1 /src/libstddjb | |
parent | 70697efff43ca5f2061d45a25abb839ad37fb3bf (diff) | |
download | skalibs-64ee50fa0e4357164273c5d8b34ccde10a69d0ef.tar.xz |
Add new sysdeps for futimens() and futimes(), adapt touch() implementation
Diffstat (limited to 'src/libstddjb')
-rw-r--r-- | src/libstddjb/touch.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 |