Add r-flag to touch(1), refactor manpage and code
and mark it as finished in README.
This commit is contained in:
parent
49ed53b46c
commit
d6b3890af6
2
README
2
README
|
@ -68,7 +68,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
=* tar non-posix none
|
=* tar non-posix none
|
||||||
=* tee yes none
|
=* tee yes none
|
||||||
test yes none
|
test yes none
|
||||||
= touch no -r
|
=* touch yes none
|
||||||
#* tr yes none
|
#* tr yes none
|
||||||
=* true yes none
|
=* true yes none
|
||||||
=* tty yes none
|
=* tty yes none
|
||||||
|
|
50
touch.1
50
touch.1
|
@ -1,4 +1,4 @@
|
||||||
.Dd January 20, 2014
|
.Dd February 9, 2014
|
||||||
.Dt TOUCH 1
|
.Dt TOUCH 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -7,25 +7,47 @@
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl acm
|
.Op Fl acm
|
||||||
.Op Fl t Ar stamp
|
.Op Fl r Ar ref_file | t Ar timestamp
|
||||||
.Ar file ...
|
.Ar file ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
sets the access and modification times of files to the current time of day. If
|
sets the access or modification time of each
|
||||||
the file doesn't exist, it is created with the default permissions.
|
.Ar file
|
||||||
|
to the current time of day. If
|
||||||
|
.Ar file
|
||||||
|
doesn't exist, it is created with default permissions.
|
||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl a
|
.It Fl a | Fl m
|
||||||
Set the access time of the file.
|
Set the access | modification time of
|
||||||
|
.Ar file.
|
||||||
.It Fl c
|
.It Fl c
|
||||||
Do not create the file it it does not exist. The exit status is not affected.
|
Don't create
|
||||||
.It Fl m
|
.Ar file
|
||||||
Change the modification time of the file.
|
if it doesn't exist, not affecting exit status.
|
||||||
.It Fl t Ar stamp
|
.It Fl r Ar ref_file
|
||||||
Set the timestamp to be used with
|
Set the timestamp
|
||||||
.Op Fl am .
|
to be used with
|
||||||
The format of the timestamp is simply the number of seconds since Jan 1, 1970.
|
.Op Fl am
|
||||||
This specification of time does not conform to POSIX.
|
to the modification time of
|
||||||
|
.Ar ref_file .
|
||||||
|
.It Fl t Ar timestamp
|
||||||
|
Set the
|
||||||
|
.Ar timestamp
|
||||||
|
to be used with
|
||||||
|
.Op Fl am
|
||||||
|
given as the number of seconds since the
|
||||||
|
Unix epoch 1970-01-01T00:00:00Z.
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr date 1
|
.Xr date 1
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
utility is compliant with the
|
||||||
|
.St -p1003.1-2008
|
||||||
|
specification except from the
|
||||||
|
.Ar timestamp
|
||||||
|
format of the
|
||||||
|
.Fl t
|
||||||
|
flag.
|
||||||
|
|
10
touch.c
10
touch.c
|
@ -46,12 +46,14 @@ touch(const char *file)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-acm] [-t stamp] file ...\n", argv0);
|
eprintf("usage: %s [-acm] [-r ref_file | -t timestamp] file ...\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
struct stat st;
|
||||||
|
char *ref;
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
|
@ -64,6 +66,12 @@ main(int argc, char *argv[])
|
||||||
case 'm':
|
case 'm':
|
||||||
mflag = 1;
|
mflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
ref = EARGF(usage());
|
||||||
|
if (stat(ref, &st) < 0)
|
||||||
|
eprintf("stat '%s':", ref);
|
||||||
|
t = st.st_mtime;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
t = estrtonum(EARGF(usage()), 0, MIN(LLONG_MAX, (time_t)-1));
|
t = estrtonum(EARGF(usage()), 0, MIN(LLONG_MAX, (time_t)-1));
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user