changeset 160:2eb41e7bf180

Use builtin functions to simplify some code in touch
author Charlie Shepherd <masterdriverz@gentoo.org>
date Sat, 10 Nov 2007 09:30:02 +0000
parents 3977fecc1b49
children b4c79ab09f9e
files toys/touch.c
diffstat 1 files changed, 9 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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;