libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2021-02-16 01:25:36
Commit3e266afeddd9391602202c9d314fe32a475a7178
Parentb8e17eee4619d3d32d9f2d0fa5817c1aaef96f69

error: Add warned flag

Add a warned flag that is set by the warn function.

Diffstat

M src/error.c | 15 +++++++++------
M src/error.h | 8 ++++++--

2 files changed, 15 insertions, 8 deletions

diff --git a/src/error.c b/src/error.c
index 6b17188..e0c80d3 100644
--- a/src/error.c
+++ b/src/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,25 +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;
 
-/* Prints an error message and exits. */
-_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);
 }
 
-/* Prints a warning message. */
+/* 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). */
+/* Shorthand for strerror(errno) */
 char *serr(void) { return strerror(errno); }
diff --git a/src/error.h b/src/error.h
index d0d4585..16db9cf 100644
--- a/src/error.h
+++ b/src/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);