aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2011-09-29 09:29:48 -0400
committerJoseph Hunkeler <jhunk@stsci.edu>2011-09-29 09:29:48 -0400
commit57d2b9b7aead6333f6eaad79a7a4338872ffab9d (patch)
tree51e48c018f079bed80a02e1ccaee9dbddb246d43 /src
parent806903aff73e3245229fda6a42054b0d6b6e0e4f (diff)
downloadduser-57d2b9b7aead6333f6eaad79a7a4338872ffab9d.tar.gz
Added touch function.
Diffstat (limited to 'src')
-rw-r--r--src/util.c23
1 files changed, 22 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
**/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
#include <ctype.h>
#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;
+}