Add r-flag to touch(1), refactor manpage and code

and mark it as finished in README.
This commit is contained in:
FRIGN
2015-02-09 00:41:57 +01:00
parent 49ed53b46c
commit d6b3890af6
3 changed files with 46 additions and 16 deletions

10
touch.c
View File

@@ -46,12 +46,14 @@ touch(const char *file)
static 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
main(int argc, char *argv[])
{
struct stat st;
char *ref;
t = time(NULL);
ARGBEGIN {
@@ -64,6 +66,12 @@ main(int argc, char *argv[])
case 'm':
mflag = 1;
break;
case 'r':
ref = EARGF(usage());
if (stat(ref, &st) < 0)
eprintf("stat '%s':", ref);
t = st.st_mtime;
break;
case 't':
t = estrtonum(EARGF(usage()), 0, MIN(LLONG_MAX, (time_t)-1));
break;