From 94ba336ee4eb934ebff8c1a6750587a3158ad549 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 25 Dec 2023 20:49:29 -0700 Subject: [PATCH] =?UTF-8?q?GNUmakefile,=20intcmp(1),=20npc(1),=20scrut(1),?= =?UTF-8?q?=20str(1),=20strcmp(1),=20include/sysexits.h:=20added=20fallbac?= =?UTF-8?q?k=20header=20file=20for=20when=20systems=20don=E2=80=99t=20have?= =?UTF-8?q?=20sysexits.h(3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GNUmakefile | 13 +++++++------ include/sysexits.h | 38 ++++++++++++++++++++++++++++++++++++++ src/intcmp.c | 4 +--- src/npc.c | 7 +------ src/scrut.c | 4 +--- src/str.c | 4 +--- src/strcmp.c | 4 +--- 7 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 include/sysexits.h diff --git a/GNUmakefile b/GNUmakefile index 29ac2bf..6dea3ae 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,22 +17,23 @@ PREFIX=/usr/local CC=cc -CFLAGS=-O3 -Lbuild/lib +CFLAGS=-O3 -Lbuild/lib -idirafter include RUSTC=rustc -RUSTCFLAGS=-C opt-level=z -C codegen-units=1 -C panic=abort -C lto=y -C strip=symbols +RUSTCFLAGS=-C opt-level=z -C codegen-units=1 -C panic=abort -C lto=y \ + -C strip=symbols ifeq ($(CC), gcc) - CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto \ - -Lbuild/lib + CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild/lib \ + -idirafter include endif ifeq ($(CC), clang) - CFLAGS=-O3 -Wall -Lbuild/lib + CFLAGS=-O3 -Wall -Lbuild/lib -idirafter include endif ifeq ($(CC), tcc) - CFLAGS=-O3 -s -Wl -flto -Lbuild/lib + CFLAGS=-O3 -s -Wl -flto -Lbuild/lib -idirafter include endif build: build_dir false intcmp scrut str strcmp true diff --git a/include/sysexits.h b/include/sysexits.h new file mode 100644 index 0000000..36f0d3d --- /dev/null +++ b/include/sysexits.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 DTB + * Copyright (c) 2023 Emma Tebibyte + * SPDX-License-Identifier: CC0 + * + * This work is marked with CC0 1.0. To view a copy of this license, visit + * . + */ + +#ifndef _SYSEXITS_H +#define _SYSEXITS_H 2 + +#ifndef EXIT_FAILURE +#include +#endif + +#define EX_OK EXIT_SUCCESS + +#define EX__BASE EXIT_FAILURE /* base value for error messages */ +#define EX_USAGE EXIT_FAILURE /* command line usage error */ +#define EX_DATAERR EXIT_FAILURE /* data format error */ +#define EX_NOINPUT EXIT_FAILURE /* cannot open input */ +#define EX_NOUSER EXIT_FAILURE /* addressee unknown */ +#define EX_NOHOST EXIT_FAILURE /* host name unknown */ +#define EX_UNAVAILABLE EXIT_FAILURE /* service unavailable */ +#define EX_SOFTWARE EXIT_FAILURE /* internal software error */ +#define EX_OSERR EXIT_FAILURE /* system error (e.g., can't fork) */ +#define EX_OSFILE EXIT_FAILURE /* critical OS file missing */ +#define EX_CANTCREAT EXIT_FAILURE /* can't create (user) output file */ +#define EX_IOERR EXIT_FAILURE /* input/output error */ +#define EX_TEMPFAIL EXIT_FAILURE /* temp failure; user is invited to retry */ +#define EX_PROTOCOL EXIT_FAILURE /* remote error in protocol */ +#define EX_NOPERM EXIT_FAILURE /* permission denied */ +#define EX_CONFIG EXIT_FAILURE /* configuration error */ + +#define EX__MAX EXIT_FAILURE /* maximum listed value */ + +#endif diff --git a/src/intcmp.c b/src/intcmp.c index e5dcdec..408474b 100644 --- a/src/intcmp.c +++ b/src/intcmp.c @@ -19,10 +19,8 @@ #include /* errno */ #include /* fprintf(3), stderr */ #include /* strtol(3), size_t, EXIT_FAILURE */ -#ifndef EX_USAGE -# define EX_USAGE EXIT_FAILURE -#endif #include /* getopt(3), optind */ +#include /* 0b00? */ /* Equal | -e | 0b001 | 1 */ #define EQUAL 0x01 /* Greater | -g | 0b010 | 2 */ diff --git a/src/npc.c b/src/npc.c index 8a07f1e..8b97180 100644 --- a/src/npc.c +++ b/src/npc.c @@ -20,12 +20,7 @@ * EOF */ #include /* EXIT_FAILURE, EXIT_SUCCESS */ #include /* getopt(3) */ -#if !defined EX_USAGE -# define EX_USAGE EXIT_FAILURE -#endif -#if !defined EX_OK -# define EX_OK EXIT_SUCCESS -#endif +#include int main(int argc, char *argv[]){ int c; diff --git a/src/scrut.c b/src/scrut.c index f2fc302..e258581 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -19,13 +19,11 @@ #include /* fprintf(3), stderr, NULL */ #include /* EXIT_FAILURE */ #include /* strchr(3) */ -#ifndef EX_USAGE -# define EX_USAGE EXIT_FAILURE -#endif #include /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */ #include /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR, * S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK, * S_ISUID, S_ISVTX */ +#include static char args[] = "bcdefghkprsuwxLS"; static char ops[(sizeof args) / (sizeof *args)]; diff --git a/src/str.c b/src/str.c index 583422d..ae03b1d 100644 --- a/src/str.c +++ b/src/str.c @@ -22,9 +22,7 @@ #include /* fprintf(3) */ #include /* EXIT_FAILURE */ #include /* strcmp(3) */ -#if !defined EX_USAGE -# define EX_USAGE EXIT_FAILURE -#endif +#include static char *program_name = "str"; diff --git a/src/strcmp.c b/src/strcmp.c index 76a2681..acb4946 100644 --- a/src/strcmp.c +++ b/src/strcmp.c @@ -1,8 +1,6 @@ #include /* fprintf(3), stderr */ #include /* EXIT_FAILURE */ -#if !defined EX_USAGE -# define EX_USAGE EXIT_FAILURE -#endif +#include static char *program_name = "strcmp";