summaryrefslogtreecommitdiff
path: root/src/libstddjb/touch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/touch.c')
-rw-r--r--src/libstddjb/touch.c37
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