From d42ed83f2173dd3f4c0571c443b7bae80577eb2b Mon Sep 17 00:00:00 2001 From: Charlie Shepherd Date: Sat, 10 Nov 2007 09:30:02 +0000 Subject: Use builtin functions to simplify some code in touch --- toys/touch.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'toys/touch.c') 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; -- cgit v1.2.3