This commit is contained in:
Connor Lane Smith
2011-05-24 01:13:34 +01:00
parent 687e5411ee
commit 9714d7b1d3
8 changed files with 103 additions and 90 deletions

22
touch.c
View File

@@ -3,7 +3,6 @@
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
@@ -18,19 +17,22 @@ static time_t t;
int
main(int argc, char *argv[])
{
int i;
char c;
t = time(NULL);
for(i = 1; i < argc; i++)
if(!strcmp(argv[i], "-c"))
while((c = getopt(argc, argv, "ct:")) != -1)
switch(c) {
case 'c':
cflag = true;
else if(!strcmp(argv[i], "-t") && i+1 < argc)
t = strtol(argv[++i], NULL, 0);
else
break;
for(; i < argc; i++)
touch(argv[i]);
case 't':
t = strtol(optarg, NULL, 0);
break;
default:
exit(EXIT_FAILURE);
}
for(; optind < argc; optind++)
touch(argv[optind]);
return EXIT_SUCCESS;
}