diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libstddjb/touch.c | 37 | ||||
-rw-r--r-- | src/sysdeps/tryfutimens.c | 12 | ||||
-rw-r--r-- | src/sysdeps/tryfutimes.c | 11 |
3 files changed, 60 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 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 ; +} |