# HG changeset patch # User Charlie Shepherd # Date 1194687002 0 # Node ID 2eb41e7bf1801a855988def079773c7f6c356718 # Parent 3977fecc1b4986e2b7915a3dfdef0d7425c0f998 Use builtin functions to simplify some code in touch diff -r 3977fecc1b49 -r 2eb41e7bf180 toys/touch.c --- a/toys/touch.c Sat Nov 10 09:10:51 2007 +0000 +++ b/toys/touch.c Sat Nov 10 09:30:02 2007 +0000 @@ -29,15 +29,9 @@ 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 @@ 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 @@ } } else { error: - perror(arg); - return 1; + perror_exit(arg); } if ((set_a+set_m) == 1) { @@ -89,10 +80,8 @@ buf.actime = sb.st_atime; } - if (utime(arg, &buf)) { - perror(arg); - return 1; - } + if (utime(arg, &buf)) + perror_exit(arg); } return 0;