diff options
| author | David E. O'Brien <obrien@FreeBSD.org> | 2001-09-22 18:45:03 +0000 |
|---|---|---|
| committer | David E. O'Brien <obrien@FreeBSD.org> | 2001-09-22 18:45:03 +0000 |
| commit | 842d1c6c964bb1177fe77b513173753042bb27c5 (patch) | |
| tree | 702a5a0324e29c17786f26baa4ee4e26a641f348 /usr.bin/touch/touch.c | |
| parent | f066622bdd23f09b5700d275c9356fa1e9d94925 (diff) | |
Notes
Diffstat (limited to 'usr.bin/touch/touch.c')
| -rw-r--r-- | usr.bin/touch/touch.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c index f8e6cce2c3ef..d5c14cbcc6ac 100644 --- a/usr.bin/touch/touch.c +++ b/usr.bin/touch/touch.c @@ -72,14 +72,18 @@ main(argc, argv) { struct stat sb; struct timeval tv[2]; + int (*stat_f)(const char *, struct stat *); + int (*utimes_f)(const char *, const struct timeval *); int aflag, cflag, fflag, mflag, ch, fd, len, rval, timeset; char *p; aflag = cflag = fflag = mflag = timeset = 0; + stat_f = stat; + utimes_f = utimes; if (gettimeofday(&tv[0], NULL)) err(1, "gettimeofday"); - while ((ch = getopt(argc, argv, "acfmr:t:")) != -1) + while ((ch = getopt(argc, argv, "acfhmr:t:")) != -1) switch(ch) { case 'a': aflag = 1; @@ -90,6 +94,11 @@ main(argc, argv) case 'f': fflag = 1; break; + case 'h': + cflag = 1; + stat_f = lstat; + utimes_f = lutimes; + break; case 'm': mflag = 1; break; @@ -134,7 +143,8 @@ main(argc, argv) for (rval = 0; *argv; ++argv) { /* See if the file exists. */ - if (stat(*argv, &sb)) { + if (stat_f(*argv, &sb) != 0) { +fprintf(stderr, "not exist\n"); if (!cflag) { /* Create the file. */ fd = open(*argv, @@ -158,7 +168,7 @@ main(argc, argv) TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec); /* Try utimes(2). */ - if (!utimes(*argv, tv)) + if (!utimes_f(*argv, tv)) continue; /* If the user specified a time, nothing else we can do. */ @@ -173,7 +183,7 @@ main(argc, argv) * The permission checks are different, too, in that the * ability to write the file is sufficient. Take a shot. */ - if (!utimes(*argv, NULL)) + if (!utimes_f(*argv, NULL)) continue; /* Try reading/writing. */ @@ -349,6 +359,6 @@ err: rval = 1; void usage() { - (void)fprintf(stderr, "usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); + (void)fprintf(stderr, "usage: touch [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); exit(1); } |
