aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-06-29 16:46:08 +0200
committerMattias Andrée <maandree@kth.se>2024-06-29 16:46:08 +0200
commit3adb84e43ad41e200beea4d3f09c4632024748fd (patch)
tree37020afa60a7adc1f55f128e76b7ed4b8cb911f0
parentFix C99 support (diff)
downloadlibsimple-3adb84e43ad41e200beea4d3f09c4632024748fd.tar.gz
libsimple-3adb84e43ad41e200beea4d3f09c4632024748fd.tar.bz2
libsimple-3adb84e43ad41e200beea4d3f09c4632024748fd.tar.xz
Add (libsimple_)_[v]e[n]printf
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile4
-rw-r--r--libsimple/printf.h143
l---------man3/libsimple__enprintf.31
l---------man3/libsimple__eprintf.31
l---------man3/libsimple__venprintf.31
l---------man3/libsimple__veprintf.31
-rw-r--r--man3/libsimple_vweprintf.385
7 files changed, 230 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index c1f2dbc..e1401b8 100644
--- a/Makefile
+++ b/Makefile
@@ -71,6 +71,10 @@ HDR =\
common.h
OBJ =\
+ _enprintf.o\
+ _eprintf.o\
+ _venprintf.o\
+ _veprintf.o\
abs.o\
abspath.o\
aligned_allocn.o\
diff --git a/libsimple/printf.h b/libsimple/printf.h
index d27a380..b6a0959 100644
--- a/libsimple/printf.h
+++ b/libsimple/printf.h
@@ -2,7 +2,8 @@
/**
- * Exit value for `libsimple_eprintf`
+ * Exit value for `libsimple_eprintf` and
+ * `libsimple__eprintf`
*
* Default value is 1
*/
@@ -250,6 +251,40 @@ libsimple_venprintf(int status__, const char *fmt__, va_list ap__)
* neither ':' nor '\n', the outpt is suffixed with
* `\n`
*
+ * This function will exit the process without
+ * calling clean-up functions registered with
+ * atexit(3)
+ *
+ * NB! This function uses `strerror` which is not
+ * thread-safe
+ *
+ * @param status Exit value for the process
+ * @param fmt The format string
+ * @param ap The format argument
+ */
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __format__(__printf__, 2, 0))))
+inline LIBSIMPLE_NORETURN void
+libsimple__venprintf(int status__, const char *fmt__, va_list ap__)
+{
+ libsimple_vweprintf(fmt__, ap__);
+ _exit(status__);
+}
+#ifndef _venprintf
+# define _venprintf libsimple__venprintf
+#endif
+
+
+/**
+ * Version of `vprintf` for printing error message;
+ * it prints to standard error (rather than standard
+ * output) and, unless `fmt` starts with "usage: "
+ * and unless `argv0` (global `char *`), prefixes
+ * the output with `"%s: ", argv0`; additionally, if
+ * `fmt` ends with ':', the output is suffixed with
+ * `" %s\n", strerror(errno)`, if `fmt` ends with
+ * neither ':' nor '\n', the outpt is suffixed with
+ * `\n`
+ *
* This function will exit the process
*
* NB! This function uses `strerror` which is not
@@ -284,6 +319,42 @@ libsimple_enprintf(int status__, const char *fmt__, ...)
* neither ':' nor '\n', the outpt is suffixed with
* `\n`
*
+ * This function will exit the process without
+ * calling clean-up functions registered with
+ * atexit(3)
+ *
+ * NB! This function uses `strerror` which is not
+ * thread-safe
+ *
+ * @param status Exit value for the process
+ * @param fmt The format string
+ * @param ... The format argument
+ */
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(2), __format__(__printf__, 2, 3))))
+inline LIBSIMPLE_NORETURN void
+libsimple__enprintf(int status__, const char *fmt__, ...)
+{
+ va_list ap__;
+ va_start(ap__, fmt__);
+ libsimple__venprintf(status__, fmt__, ap__);
+ va_end(ap__);
+}
+#ifndef _enprintf
+# define _enprintf libsimple__enprintf
+#endif
+
+
+/**
+ * Version of `vprintf` for printing error message;
+ * it prints to standard error (rather than standard
+ * output) and, unless `fmt` starts with "usage: "
+ * and unless `argv0` (global `char *`), prefixes
+ * the output with `"%s: ", argv0`; additionally, if
+ * `fmt` ends with ':', the output is suffixed with
+ * `" %s\n", strerror(errno)`, if `fmt` ends with
+ * neither ':' nor '\n', the outpt is suffixed with
+ * `\n`
+ *
* This function will exit the process with the
* value `libsimple_default_failure_exit`
*
@@ -317,6 +388,40 @@ libsimple_veprintf(const char *fmt__, va_list ap__)
* `\n`
*
* This function will exit the process with the
+ * value `libsimple_default_failure_exit` without
+ * calling clean-up functions registered with
+ * atexit(3)
+ *
+ * NB! This function uses `strerror` which is not
+ * thread-safe
+ *
+ * @param fmt The format string
+ * @param ap The format argument
+ */
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 0))))
+inline LIBSIMPLE_NORETURN void
+libsimple__veprintf(const char *fmt__, va_list ap__)
+{
+ libsimple_vweprintf(fmt__, ap__);
+ _exit(libsimple_default_failure_exit);
+}
+#ifndef _veprintf
+# define _veprintf libsimple__veprintf
+#endif
+
+
+/**
+ * Version of `vprintf` for printing error message;
+ * it prints to standard error (rather than standard
+ * output) and, unless `fmt` starts with "usage: "
+ * and unless `argv0` (global `char *`), prefixes
+ * the output with `"%s: ", argv0`; additionally, if
+ * `fmt` ends with ':', the output is suffixed with
+ * `" %s\n", strerror(errno)`, if `fmt` ends with
+ * neither ':' nor '\n', the outpt is suffixed with
+ * `\n`
+ *
+ * This function will exit the process with the
* value `libsimple_default_failure_exit`
*
* NB! This function uses `strerror` which is not
@@ -337,3 +442,39 @@ libsimple_eprintf(const char *fmt__, ...)
#ifndef eprintf
# define eprintf libsimple_eprintf
#endif
+
+
+/**
+ * Version of `vprintf` for printing error message;
+ * it prints to standard error (rather than standard
+ * output) and, unless `fmt` starts with "usage: "
+ * and unless `argv0` (global `char *`), prefixes
+ * the output with `"%s: ", argv0`; additionally, if
+ * `fmt` ends with ':', the output is suffixed with
+ * `" %s\n", strerror(errno)`, if `fmt` ends with
+ * neither ':' nor '\n', the outpt is suffixed with
+ * `\n`
+ *
+ * This function will exit the process with the
+ * value `libsimple_default_failure_exit` without
+ * calling clean-up functions registered with
+ * atexit(3)
+ *
+ * NB! This function uses `strerror` which is not
+ * thread-safe
+ *
+ * @param fmt The format string
+ * @param ... The format argument
+ */
+LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __format__(__printf__, 1, 2))))
+inline LIBSIMPLE_NORETURN void
+libsimple__eprintf(const char *fmt__, ...)
+{
+ va_list ap__;
+ va_start(ap__, fmt__);
+ libsimple__veprintf(fmt__, ap__);
+ va_end(ap__);
+}
+#ifndef _eprintf
+# define _eprintf libsimple__eprintf
+#endif
diff --git a/man3/libsimple__enprintf.3 b/man3/libsimple__enprintf.3
new file mode 120000
index 0000000..3d2d430
--- /dev/null
+++ b/man3/libsimple__enprintf.3
@@ -0,0 +1 @@
+libsimple_enprintf.3 \ No newline at end of file
diff --git a/man3/libsimple__eprintf.3 b/man3/libsimple__eprintf.3
new file mode 120000
index 0000000..07276cb
--- /dev/null
+++ b/man3/libsimple__eprintf.3
@@ -0,0 +1 @@
+libsimple_eprintf.3 \ No newline at end of file
diff --git a/man3/libsimple__venprintf.3 b/man3/libsimple__venprintf.3
new file mode 120000
index 0000000..574bdd9
--- /dev/null
+++ b/man3/libsimple__venprintf.3
@@ -0,0 +1 @@
+libsimple_venprintf.3 \ No newline at end of file
diff --git a/man3/libsimple__veprintf.3 b/man3/libsimple__veprintf.3
new file mode 120000
index 0000000..3a87c2d
--- /dev/null
+++ b/man3/libsimple__veprintf.3
@@ -0,0 +1 @@
+libsimple_veprintf.3 \ No newline at end of file
diff --git a/man3/libsimple_vweprintf.3 b/man3/libsimple_vweprintf.3
index b40799d..bd11957 100644
--- a/man3/libsimple_vweprintf.3
+++ b/man3/libsimple_vweprintf.3
@@ -16,6 +16,10 @@ inline void libsimple_venprintf(int \fIstatus\fP, const char *\fIfmt\fP, va_list
inline void libsimple_enprintf(int \fIstatus\fP, const char *\fIfmt\fP, ...);
inline void libsimple_veprintf(const char *\fIfmt\fP, va_list \fIap\fP);
inline void libsimple_eprintf(const char *\fIfmt\fP, ...);
+inline void libsimple__venprintf(int \fIstatus\fP, const char *\fIfmt\fP, va_list \fIap\fP);
+inline void libsimple__enprintf(int \fIstatus\fP, const char *\fIfmt\fP, ...);
+inline void libsimple__veprintf(const char *\fIfmt\fP, va_list \fIap\fP);
+inline void libsimple__eprintf(const char *\fIfmt\fP, ...);
#ifndef vweprintf
# define vweprintf libsimple_vweprintf
@@ -35,6 +39,18 @@ inline void libsimple_eprintf(const char *\fIfmt\fP, ...);
#ifndef eprintf
# define eprintf libsimple_eprintf
#endif
+#ifndef _venprintf
+# define _venprintf libsimple__venprintf
+#endif
+#ifndef _enprintf
+# define _enprintf libsimple__enprintf
+#endif
+#ifndef _veprintf
+# define _veprintf libsimple__veprintf
+#endif
+#ifndef _eprintf
+# define _eprintf libsimple__eprintf
+#endif
.fi
.PP
Link with
@@ -102,6 +118,19 @@ the exit value of the process will be
.IR status .
.PP
The
+.BR libsimple__venprintf ()
+and
+.BR libsimple__enprintf ()
+functions are versions of the
+.BR libsimple_vweprintf ()
+and
+.BR libsimple_weprintf ()
+functions that terminate the process by calling
+.BR _exit (3),
+the exit value of the process will be
+.IR status .
+.PP
+The
.BR libsimple_veprintf ()
and
.BR libsimple_eprintf ()
@@ -116,13 +145,31 @@ the exit value of the process will be
which is 1 by default.
.PP
The
+.BR libsimple__veprintf ()
+and
+.BR libsimple__eprintf ()
+functions are versions of the
+.BR libsimple_vweprintf ()
+and
+.BR libsimple_weprintf ()
+functions that terminate the process by calling
+.BR _exit (3),
+the exit value of the process will be
+.IR libsimple_default_failure_exit (3),
+which is 1 by default.
+.PP
+The
.BR libsimple_vweprintf (),
.BR libsimple_weprintf (),
.BR libsimple_venprintf (),
.BR libsimple_enprintf (),
.BR libsimple_veprintf (),
+.BR libsimple_eprintf (),
+.BR libsimple__venprintf (),
+.BR libsimple__enprintf (),
+.BR libsimple__veprintf (),
and
-.BR libsimple_eprintf ()
+.BR libsimple__eprintf ()
functions call
.I libsimple_eprintf_preprint
unless it is
@@ -146,8 +193,12 @@ may have a different value from when the
.BR libsimple_venprintf (),
.BR libsimple_enprintf (),
.BR libsimple_veprintf (),
+.BR libsimple_eprintf (),
+.BR libsimple__venprintf (),
+.BR libsimple__enprintf (),
+.BR libsimple__veprintf (),
or
-.BR libsimple_eprintf ()
+.BR libsimple__eprintf ()
function called when
.I libsimple_eprintf_preprint
or
@@ -179,7 +230,15 @@ T{
.br
.BR libsimple_veprintf (),
.br
-.BR libsimple_eprintf ()
+.BR libsimple_eprintf (),
+.br
+.BR libsimple__venprintf (),
+.br
+.BR libsimple__enprintf (),
+.br
+.BR libsimple__veprintf (),
+.br
+.BR libsimple__eprintf ()
T} Thread safety MT-Unsafe race:strerror
T{
.BR libsimple_vweprintf (),
@@ -192,7 +251,15 @@ T{
.br
.BR libsimple_veprintf (),
.br
-.BR libsimple_eprintf ()
+.BR libsimple_eprintf (),
+.br
+.BR libsimple__venprintf (),
+.br
+.BR libsimple__enprintf (),
+.br
+.BR libsimple__veprintf (),
+.br
+.BR libsimple__eprintf ()
T} Async-signal safety AS-Safe
T{
.BR libsimple_vweprintf (),
@@ -205,7 +272,15 @@ T{
.br
.BR libsimple_veprintf (),
.br
-.BR libsimple_eprintf ()
+.BR libsimple_eprintf (),
+.br
+.BR libsimple__venprintf (),
+.br
+.BR libsimple__enprintf (),
+.br
+.BR libsimple__veprintf (),
+.br
+.BR libsimple__eprintf ()
T} Async-cancel safety AC-Safe
.TE