coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2020-07-06 11:46:31
Commite8367edd416d339940811f92ab3a852730d574f0
Parenta87087e83ee8abc661f815881c4b194c61454188

touch: Use libokv error reporting

Diffstat

M src/touch.c | 30 +++++++++++++++---------------

1 files changed, 15 insertions, 15 deletions

diff --git a/src/touch.c b/src/touch.c
index 13a7bab..3d3a36e 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -1,4 +1,4 @@
-// touch.c, version 1.0.0
+// touch.c, version 1.0.1
 // OMKOV coreutils implementation of POSIX touch
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -39,9 +39,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 
 #define _XOPEN_SOURCE 700
 
-#include "error.h"
 #include "optget.h"
 
+#include <error.h>
+
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -50,9 +51,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
 
-static const char *ARG0;
+#define VERSION "1.0.1"
 
 static bool aflag, cflag, mflag;
 static bool rflag, notnow;
@@ -68,7 +68,7 @@ static inline int touch(const char *file);
 static void help(void);
 static void version(void);
 
-int main(int argc, char *argv[]) { ARG0 = argv[0];
+int main(int ac, char *av[]) { A0 = av[0];
 	lop_t lops[] = {
 		{ "help",    ARG_NUL, 256 },
 		{ "version", ARG_NUL, 257 },
@@ -76,7 +76,7 @@ int main(int argc, char *argv[]) { ARG0 = argv[0];
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "acd:mr:t:"; opt.lops = lops; int o;
-	while ((o = optget(&opt, argv, 1)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 1)) != -1) switch (o) {
 	case 'a': { aflag = true; break; }
 	case 'c': { cflag = true; break; }
 	case 'd': { if (notnow) { goto invalid; } dparse(opt.arg); break; }
@@ -86,10 +86,10 @@ int main(int argc, char *argv[]) { ARG0 = argv[0];
 	case 256: { help(); return 0; }
 	case 257: { version(); return 0; }
 	default: { return 1; }
-	invalid: { error(1, "%s: invalid option combination", argv[0]); }
+	invalid: { error(1, "invalid option combination"); }
 	}
 
-	if (opt.ind == argc) { error(1, "%s: missing operand", argv[0]); }
+	if (opt.ind == ac) { error(1, "missing operand"); }
 
 	if (!rflag) { times[1] = times[0]; }
 	if (!aflag && !mflag) { aflag = mflag = true; }
@@ -98,8 +98,8 @@ int main(int argc, char *argv[]) { ARG0 = argv[0];
 
 	bool warned = false;
 
-	for (char **p = &argv[opt.ind]; *p; ++p) if (touch(*p)) {
-		warn("%s: %s: %s", argv[0], *p, serrno); warned = true;
+	for (char **p = &av[opt.ind]; *p; ++p) if (touch(*p)) {
+		warn("%s: %s", *p, serr()); warned = true;
 	}
 
 	return warned;
@@ -112,7 +112,7 @@ static inline void dparse(const char *str) {
 	if (len == 19 && strptime(str, "%Y-%m-%dT%H:%M:%S", &t));
 	else if (len == 20 && strptime(str, "%Y-%m-%dT%H:%M:%SZ", &t)) {
 		tzset(); t.tm_sec -= timezone;
-	} else { error(1, "%s: %s: invalid time format", ARG0, str); }
+	} else { error(1, "%s: invalid time format", str); }
 
 	struct timespec ts; ts.tv_sec = mktime(&t); ts.tv_nsec = 0;
 	times[0] = ts; notnow = true; return;
@@ -121,7 +121,7 @@ static inline void dparse(const char *str) {
 static inline void tparse(const char *str) {
 	time_t now; struct tm *cur, t = { 0 };
 	if ((now = time(NULL)) == -1 || !(cur = localtime(&now))) {
-		error(1, "%s: %s: %s", ARG0, str, serrno);
+		error(1, "%s: %s", str, serr());
 	} t.tm_isdst = -1;
 
 	register size_t len = strlen(str);
@@ -131,7 +131,7 @@ static inline void tparse(const char *str) {
 	else if (len == 12 && strptime(str, "%Y%m%d%H%M", &t));
 	else if (len == 13 && strptime(str, "%y%m%d%H%M.%S", &t));
 	else if (len == 15 && strptime(str, "%Y%m%d%H%M.%S", &t));
-	else { error(1, "%s: %s: invalid time format", ARG0, str); }
+	else { error(1, "%s: invalid time format", str); }
 
 	struct timespec ts; ts.tv_sec = mktime(&t); ts.tv_nsec = 0;
 	times[0] = ts; notnow = true; return;
@@ -139,7 +139,7 @@ static inline void tparse(const char *str) {
 
 static inline void rparse(const char *file) {
 	struct stat fs; if (stat(file, &fs)) {
-		error(1, "%s: %s: %s", ARG0, file, serrno);
+		error(1, "%s: %s", file, serr());
 	} times[0] = fs.st_atim; times[1] = fs.st_mtim;
 	rflag = true; notnow = true; return;
 }
@@ -169,7 +169,7 @@ static void help(void) {
 }
 
 static void version(void) {
-	puts("OMKOV coreutils touch, version 1.0.0");
+	puts("OMKOV coreutils touch, version " VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");
 	puts("All rights reserved.");
 	puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");