Usage: print base name of program.
-A flag: respect the -a and -m flags. imply the -c flag. Requested in principle by: brian
This commit is contained in:
parent
5d2d083c92
commit
1b54381b5a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=168571
@ -52,6 +52,7 @@ static const char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93";
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -76,7 +77,7 @@ main(int argc, char *argv[])
|
|||||||
char *p;
|
char *p;
|
||||||
char *myname;
|
char *myname;
|
||||||
|
|
||||||
myname = argv[0];
|
myname = basename(argv[0]);
|
||||||
Aflag = aflag = cflag = fflag = mflag = timeset = 0;
|
Aflag = aflag = cflag = fflag = mflag = timeset = 0;
|
||||||
stat_f = stat;
|
stat_f = stat;
|
||||||
utimes_f = utimes;
|
utimes_f = utimes;
|
||||||
@ -120,30 +121,46 @@ main(int argc, char *argv[])
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
/* -a and -m are default unless one of them or -A is set. */
|
if (aflag == 0 && mflag == 0)
|
||||||
if (aflag == 0 && mflag == 0 && Aflag == 0)
|
|
||||||
aflag = mflag = 1;
|
aflag = mflag = 1;
|
||||||
|
|
||||||
/*
|
if (timeset) {
|
||||||
* If no -r or -t flag, at least two operands, the first of which
|
if (Aflag) {
|
||||||
* is an 8 or 10 digit number, use the obsolete time specification.
|
/*
|
||||||
*/
|
* We're setting the time to an offset from a specified
|
||||||
if (!timeset && argc > 1) {
|
* time. God knows why, but it means that we can set
|
||||||
(void)strtol(argv[0], &p, 10);
|
* that time once and for all here.
|
||||||
len = p - argv[0];
|
*/
|
||||||
if (*p == '\0' && (len == 8 || len == 10)) {
|
if (aflag)
|
||||||
timeset = 1;
|
tv[0].tv_sec += Aflag;
|
||||||
stime_arg2(*argv++, len == 10, tv);
|
if (mflag)
|
||||||
|
tv[1].tv_sec += Aflag;
|
||||||
|
Aflag = 0; /* done our job */
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
/*
|
||||||
/* Otherwise use the current time of day. */
|
* If no -r or -t flag, at least two operands, the first of
|
||||||
if (!timeset)
|
* which is an 8 or 10 digit number, use the obsolete time
|
||||||
|
* specification, otherwise use the current time.
|
||||||
|
*/
|
||||||
|
if (argc > 1) {
|
||||||
|
strtol(argv[0], &p, 10);
|
||||||
|
len = p - argv[0];
|
||||||
|
if (*p == '\0' && (len == 8 || len == 10)) {
|
||||||
|
timeset = 1;
|
||||||
|
stime_arg2(*argv++, len == 10, tv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Both times default to the same. */
|
||||||
tv[1] = tv[0];
|
tv[1] = tv[0];
|
||||||
|
}
|
||||||
|
|
||||||
if (*argv == NULL)
|
if (*argv == NULL)
|
||||||
usage(myname);
|
usage(myname);
|
||||||
|
|
||||||
|
if (Aflag)
|
||||||
|
cflag = 1;
|
||||||
|
|
||||||
for (rval = 0; *argv; ++argv) {
|
for (rval = 0; *argv; ++argv) {
|
||||||
/* See if the file exists. */
|
/* See if the file exists. */
|
||||||
if (stat_f(*argv, &sb) != 0) {
|
if (stat_f(*argv, &sb) != 0) {
|
||||||
@ -164,14 +181,24 @@ main(int argc, char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If -a or -m are not set, base time on current file time. */
|
|
||||||
if (!aflag)
|
if (!aflag)
|
||||||
TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
|
TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
|
||||||
if (!mflag)
|
if (!mflag)
|
||||||
TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
|
TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We're adjusting the times based on the file times, not a
|
||||||
|
* specified time (that gets handled above).
|
||||||
|
*/
|
||||||
if (Aflag) {
|
if (Aflag) {
|
||||||
tv[0].tv_sec += Aflag;
|
if (aflag) {
|
||||||
tv[1].tv_sec += Aflag;
|
TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
|
||||||
|
tv[0].tv_sec += Aflag;
|
||||||
|
}
|
||||||
|
if (mflag) {
|
||||||
|
TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
|
||||||
|
tv[1].tv_sec += Aflag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try utimes(2). */
|
/* Try utimes(2). */
|
||||||
|
Loading…
Reference in New Issue
Block a user