coreutils

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

AuthorJamozed <[email protected]>
Date2020-07-06 11:40:13
Commit601b288ba723e2500a54eec45ce5381e2c34dfac
Parent911e33a0feeb786216ef67c96c5b47106df01ab2

tee: Use libokv error reporting

Diffstat

M src/tee.c | 26 ++++++++++++--------------

1 files changed, 12 insertions, 14 deletions

diff --git a/src/tee.c b/src/tee.c
index 7758ad8..f837b01 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -1,4 +1,4 @@
-// tee.c, version 1.0.2
+// tee.c, version 1.0.3
 // OMKOV coreutils implementation of POSIX tee
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,23 +33,23 @@ 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 <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
+#include <stdlib.h>
 
-#define VERSION "1.0.2"
+#define VERSION "1.0.3"
 
 static bool aflag;
 
 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 },
@@ -57,7 +57,7 @@ int main(int argc, char *argv[]) {
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "ai"; 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 'i': { signal(SIGINT, SIG_IGN); break; }
 	case 256: { help(); return 0; }
@@ -68,13 +68,13 @@ int main(int argc, char *argv[]) {
 	setvbuf(stdout, NULL, _IONBF, 0);
 	bool warned = false;
 
-	FILE **files = (FILE **)malloc(sizeof (FILE) * (argc - opt.ind));
-	if (!files) { error(1, "%s: %s", argv[0], serrno); }
+	FILE **files = (FILE **)malloc(sizeof (FILE) * (ac - opt.ind));
+	if (!files) { error(1, "%s", serr()); }
 
 	FILE **f = files;
-	for (char **p = &argv[opt.ind]; *p; ++p, ++f) {
+	for (char **p = &av[opt.ind]; *p; ++p, ++f) {
 		*f = fopen(*p, aflag ? "w" : "a");
-		if (!*f) { warn("%s: %s: %s", argv[0], *p, serrno); --f; }
+		if (!*f) { warn("%s: %s", *p, serr()); --f; }
 	} *f = NULL;
 
 	char stdbuf[BUFSIZ * 16];
@@ -83,9 +83,7 @@ int main(int argc, char *argv[]) {
 		fwrite(stdbuf, 1, c, stdout);
 	}
 
-	for (f = files; *f; ++f) {
-		if (fclose(*f)) { warn("%s: %s", argv[0], serrno); }
-	}
+	for (f = files; *f; ++f) { if (fclose(*f)) { warn("%s", serr()); }}
 
 	free(files); return warned;
 }