coreutils

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

AuthorJamozed <[email protected]>
Date2020-07-06 11:04:27
Commit2e3f63023ca450ddc64b742fed1304922c8a214d
Parent76371b717ade76542fd0be74fd725b8518493bab

nice: Use libokv error reporting

Diffstat

M src/nice.c | 27 ++++++++++++++-------------

1 files changed, 14 insertions, 13 deletions

diff --git a/src/nice.c b/src/nice.c
index f5b98d4..6e48675 100644
--- a/src/nice.c
+++ b/src/nice.c
@@ -1,4 +1,4 @@
-// nice.c, version 1.0.0
+// nice.c, version 1.0.1
 // OMKOV coreutils implementation of POSIX nice
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,23 +33,25 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
-#include "error.h"
 #include "optget.h"
 
+#include <error.h>
+
 #include <unistd.h>
 
 #include <errno.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
+
+#define VERSION "1.0.1"
 
 static int n = 10;
 
 static inline void help(void);
 static inline void version(void);
 
-int main(int argc, char *argv[]) {
+int main(int ac, char *av[]) { A0 = av[0];
 	lop_t lops[] = {
 		{ "help",    ARG_NUL, 256 },
 		{ "version", ARG_NUL, 257 },
@@ -57,7 +59,7 @@ int main(int argc, char *argv[]) {
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "n:"; opt.lops = lops; int o;
-	while ((o = optget(&opt, argv, 0)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 0)) != -1) switch (o) {
 	case 'n': {
 		register int d; register char *p = opt.arg; bool neg = false;
 		if (*p == '-') { neg = true; ++p; } else if (*p == '+') { ++p; }
@@ -67,7 +69,7 @@ int main(int argc, char *argv[]) {
 			n = n * 10 + d;
 		}
 
-		if (*p) { error(1, "%s: %s: invalid nice value", argv[0], opt.arg); }
+		if (*p) { error(1, "%s: invalid nice value", opt.arg); }
 		if (neg) { n = -n; } break;
 	}
 	case 256: { help(); return 0; }
@@ -75,13 +77,13 @@ int main(int argc, char *argv[]) {
 	default: { return 1; }
 	}
 
-	if (argc == 1) { printf("%d\n", nice(0)); return 0; }
-	else if (opt.ind == argc) { error(1, "%s: missing operand\n", argv[0]); }
+	if (ac == 1) { printf("%d\n", nice(0)); return 0; }
+	else if (opt.ind == ac) { error(1, "missing operand\n"); }
 
-	errno = 0; nice(n); if (errno) { warn("%s: %s", argv[0], serrno); }
-	execvp(argv[opt.ind], &argv[opt.ind]);
+	errno = 0; nice(n); if (errno) { warn("%s", serr()); }
+	execvp(av[opt.ind], &av[opt.ind]);
 
-	warn("%s: %s: %s", argv[0], argv[opt.ind], serrno);
+	warn("%s: %s", av[opt.ind], serr());
 	return errno = ENOENT ? 127 : 126;
 }
 
@@ -96,7 +98,7 @@ static inline void help(void) {
 }
 
 static inline void version() {
-	puts("OMKOV coreutils nice, version 1.0.0");
+	puts("OMKOV coreutils nice, version " VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");
 	puts("All rights reserved.");
 	puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");