k9core

Coreutils for *nix operating systems [fork]
git clone git://bvnf.space/k9core.git
Log | Files | Refs | LICENSE

touch.c (383B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	if(argc != 2) {
		fprintf(stderr, "usage: touch file\n");
		return 1;
	}

	int fd = creat(argv[1], 0644);

	if(fd == -1) {
		fprintf(stderr, "touch: %s: %s\n", argv[1], strerror(errno));
		return 1;
	}
	close(fd);
	return 0;
}