From 57d2b9b7aead6333f6eaad79a7a4338872ffab9d Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 29 Sep 2011 09:29:48 -0400 Subject: Added touch function. --- src/util.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/util.c b/src/util.c index 4d5f58c..ed0fa56 100644 --- a/src/util.c +++ b/src/util.c @@ -18,10 +18,12 @@ * along with duser. If not, see . **/ -#define _GNU_SOURCE #include #include #include +#include +#include +#include #include #include "duser.h" @@ -93,3 +95,22 @@ int strval(const char* str) return 0; } +int touch(const char* filename, mode_t mode) +{ + size_t bytes = 0; + int fd = -1; + + if((fd = open(filename, O_CREAT | O_WRONLY, mode)) < 0) + { + COM(SELF, "FATAL: %s: %s: %s\n", filename, strerror(errno)); + fprintf(stderr, "FATAL: %s: %s: %s\n", SELF, filename, strerror(errno)); + return errno; + } + char byte = '\0'; + if((bytes = write(fd, &byte, 1)) < 1) + { + return errno; + } + close(fd); + return 0; +} -- cgit