Author | Jamozed <[email protected]> |
Date | 2021-02-16 01:28:04 |
Commit | f072a5b059f337d8d5ed986b4d7f5268b8edee1c |
Parent | fdcdee76f5222273238f9cffcaa1b7461c324d2a |
lib: Update error to version 1.0.2
Diffstat
M | src/chmod.c | | | 5 | ++--- |
M | src/lib/error.c | | | 12 | +++++++++--- |
M | src/lib/error.h | | | 8 | ++++++-- |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/chmod.c b/src/chmod.c index a301e9a..4afbbbd 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -1,4 +1,4 @@ -// chmod.c, version 1.0.1 +// chmod.c, version 1.0.2 // OMKOV coreutils implementation of POSIX chmod // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -49,7 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include <stdlib.h> #include <string.h> -#define VERSION "1.0.1" +#define VERSION "1.0.2" static struct lop lops[] = { { "help", ARG_NUL, 256 }, @@ -60,7 +60,6 @@ static struct lop lops[] = { static bool Rflag; static mode_t mask; -static bool warned = false; static inline int setmode(const char *path, chmod_t *m); static inline char *mkpath(const char *path, const char *file); diff --git a/src/lib/error.c b/src/lib/error.c index f246723..e0c80d3 100644 --- a/src/lib/error.c +++ b/src/lib/error.c @@ -1,4 +1,4 @@ -// error.c, version 1.0.1 +// error.c, version 1.0.2 // Error source file for OMKOV lib // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -34,22 +34,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include <errno.h> #include <stdarg.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <stdnoreturn.h> #include <string.h> char *A0 = NULL; +bool warned = false; -_Noreturn void error(int status, const char *format, ...) { +/* Print an error message and exit */ +noreturn void error(int status, const char *format, ...) { fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); } va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); fputc('\n', stderr); exit(status); } +/* Print a warning message and set the warned flag */ void warn(const char *format, ...) { fflush(stdout); if (A0) { fputs(A0, stderr); fputs(": ", stderr); } va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); - fputc('\n', stderr); return; + fputc('\n', stderr); warned = true; return; } +/* Shorthand for strerror(errno) */ char *serr(void) { return strerror(errno); } diff --git a/src/lib/error.h b/src/lib/error.h index d0d4585..16db9cf 100644 --- a/src/lib/error.h +++ b/src/lib/error.h @@ -1,4 +1,4 @@ -// error.h, version 1.0.1 +// error.h, version 1.0.2 // Error header file for OMKOV lib // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -33,9 +33,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #ifndef OMKOV_LIB_ERROR_H_38W06M3W #define OMKOV_LIB_ERROR_H_38W06M3W +#include <stdbool.h> +#include <stdnoreturn.h> + extern char *A0; +extern bool warned; -extern _Noreturn void error(int status, const char *format, ...); +extern noreturn void error(int status, const char *format, ...); extern void warn(const char *format, ...); extern char *serr(void);