diff options
author | Charlie Shepherd <masterdriverz@gentoo.org> | 2007-11-10 09:30:02 +0000 |
---|---|---|
committer | Charlie Shepherd <masterdriverz@gentoo.org> | 2007-11-10 09:30:02 +0000 |
commit | d42ed83f2173dd3f4c0571c443b7bae80577eb2b (patch) | |
tree | 2319063360d59e3307470596715bba41d03fe83e /toys | |
parent | d3ab5f0798f3e1fde5f0f6778bf48f03579c7e98 (diff) | |
download | toybox-d42ed83f2173dd3f4c0571c443b7bae80577eb2b.tar.gz |
Use builtin functions to simplify some code in touch
Diffstat (limited to 'toys')
-rw-r--r-- | toys/touch.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/toys/touch.c b/toys/touch.c index 6771877b..0b5b2276 100644 --- a/toys/touch.c +++ b/toys/touch.c @@ -29,15 +29,9 @@ int touch_main(void) if (toys.optflags & REFERENCE) { struct stat sb; - if (toys.optflags & TIME) { - fprintf(stderr, - "Cannot specify times from more than one source\n"); - return 1; - } - if (stat(toy.touch.ref_file, &sb) == -1) { - perror(toy.touch.ref_file); - return 1; - } + if (toys.optflags & TIME) + error_exit("Cannot specify times from more than one source"); + xstat(toy.touch.ref_file, &sb); curr_m = sb.st_mtime; curr_a = sb.st_atime; } else if (toys.optflags & TIME) { @@ -51,12 +45,10 @@ int touch_main(void) if (!c || *c) goto err; curr_a = curr_m = mktime(&t); - if (curr_a == -1) { + if (curr_a == -1) err: - fprintf(stderr, "Error converting time %s to internal format", - toy.touch.time); - return 1; - } + error_exit("Error converting time %s to internal format", + toy.touch.time); } else { curr_m = curr_a = time(NULL); } @@ -77,8 +69,7 @@ err: } } else { error: - perror(arg); - return 1; + perror_exit(arg); } if ((set_a+set_m) == 1) { @@ -89,10 +80,8 @@ error: buf.actime = sb.st_atime; } - if (utime(arg, &buf)) { - perror(arg); - return 1; - } + if (utime(arg, &buf)) + perror_exit(arg); } return 0; |