coreutils

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

AuthorJamozed <[email protected]>
Date2020-07-06 10:38:51
Commite013c3eb3ad4e5d1205ea0f26aeea34b5797e26f
Parent39afcc422fe1078e944a1f0ee62d5bd9de44424d

head: Use libokv error reporting

Diffstat

M src/head.c | 23 +++++++++++------------

1 files changed, 11 insertions, 12 deletions

diff --git a/src/head.c b/src/head.c
index 33e0a30..ee30493 100644
--- a/src/head.c
+++ b/src/head.c
@@ -1,4 +1,4 @@
-// head.c, version 1.0.2
+// head.c, version 1.0.3
 // OMKOV coreutils implementation of POSIX head
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,16 +33,15 @@ 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 <errno.h>
+#include <error.h>
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <string.h>
 
-#define VERSION "1.0.2"
+#define VERSION "1.0.3"
 
 static uintmax_t limit = 10;
 static bool      label;
@@ -52,7 +51,7 @@ static inline int head(const char *path);
 static void help(void);
 static 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 },
@@ -60,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, 1)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 1)) != -1) switch (o) {
 	case 'n': {
 		register uintmax_t d; register char *p = opt.arg;
 		for (limit = 0; *p >= '0' && *p <= '9'; ++p) {
@@ -69,7 +68,7 @@ int main(int argc, char *argv[]) {
 			limit = limit * 10 + d;
 		}
 
-		if (*p) { error(1, "%s: %s: invalid line count", argv[0], opt.arg); }
+		if (*p) { error(1, "%s: invalid line count", opt.arg); }
 		break;
 	}
 	case 256: { help(); return 0; }
@@ -79,10 +78,10 @@ int main(int argc, char *argv[]) {
 
 	bool warned = false;
 
-	if (opt.ind == argc) { head("-"); return 0; }
-	if (opt.ind + 1 != argc) { label = true; }
-	for (char **p = &argv[opt.ind]; *p; ++p) if (head(*p)) {
-		warn("%s: %s: %s", argv[0], *p, serrno); warned = true;
+	if (opt.ind == ac) { head("-"); return 0; }
+	if (opt.ind + 1 != ac) { label = true; }
+	for (char **p = &av[opt.ind]; *p; ++p) if (head(*p)) {
+		warn("%s: %s", *p, serr()); warned = true;
 	}
 
 	return warned;