Eliminating the getopt disgrace.

This commit is contained in:
Christoph Lohmann
2013-06-14 20:20:47 +02:00
parent 75c97de593
commit 4d38f60685
28 changed files with 724 additions and 476 deletions

39
touch.c
View File

@@ -14,26 +14,32 @@ static void touch(const char *);
static bool cflag = false;
static time_t t;
static void
usage(void)
{
eprintf("usage: %s [-c] [-t stamp] file...\n", argv0);
exit(1);
}
int
main(int argc, char *argv[])
{
char c;
t = time(NULL);
while((c = getopt(argc, argv, "ct:")) != -1)
switch(c) {
case 'c':
cflag = true;
break;
case 't':
t = estrtol(optarg, 0);
break;
default:
exit(EXIT_FAILURE);
}
for(; optind < argc; optind++)
touch(argv[optind]);
return EXIT_SUCCESS;
ARGBEGIN {
case 'c':
cflag = true;
break;
case 't':
t = estrtol(EARGF(usage()), 0);
break;
default:
usage();
} ARGEND;
for(; argc > 0; argc--, argv++)
touch(argv[0]);
return 0;
}
void
@@ -60,3 +66,4 @@ touch(const char *str)
close(fd);
touch(str);
}