mailing list of musl libc
 help / color / mirror / code / Atom feed
* [RFC] Implement errc/warnc family of functions
@ 2014-06-13  6:06 Isaac Dunham
  2014-06-13  8:56 ` Justin Cormack
  2014-06-13 16:33 ` Rich Felker
  0 siblings, 2 replies; 5+ messages in thread
From: Isaac Dunham @ 2014-06-13  6:06 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

I was trying to build netbsd sed, and it needed errc.
So I wrote an errc implementation.

I'm not sure if the output has the proper format; I haven't had a chance
to see what output is like on other libcs.
This says
progname: fmt: strerror
(and no newline).
Also, this may belong in src/legacy/err.c.
If I did this right, vwarn could share a bit of code with it.

thanks,
Isaac Dunham

[-- Attachment #2: errc.diff --]
[-- Type: text/plain, Size: 1913 bytes --]

commit b80ac849cae653425979baf8a29c800412ca7aec
Author: Isaac Dunham <idunham@lavabit.com>
Date:   Thu Jun 12 19:44:01 2014 -0700

    Implement (v){warn,err}c interfaces.
    
    These are a newish BSD addition to allow using error sources other than
    errno with the err.h interface.

diff --git a/include/err.h b/include/err.h
index 9f5cb6b..0ae6036 100644
--- a/include/err.h
+++ b/include/err.h
@@ -12,11 +12,15 @@ void warn(const char *, ...);
 void vwarn(const char *, va_list);
 void warnx(const char *, ...);
 void vwarnx(const char *, va_list);
+void warnc(int error, const char *fmt, ...);
+void vwarnc(int error, const char *fmt, va_list ap);
 
 _Noreturn void err(int, const char *, ...);
 _Noreturn void verr(int, const char *, va_list);
 _Noreturn void errx(int, const char *, ...);
 _Noreturn void verrx(int, const char *, va_list);
+_Noreturn void errc(int status, int error, const char *fmt, ...);
+_Noreturn void verrc(int status, int error, const char *fmt, va_list ap);
 
 #ifdef __cplusplus
 }
diff --git a/src/legacy/errc.c b/src/legacy/errc.c
new file mode 100644
index 0000000..084a761
--- /dev/null
+++ b/src/legacy/errc.c
@@ -0,0 +1,39 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern char *__progname;
+
+void vwarnc(int error, const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", __progname);
+	if (fmt) {
+		vfprintf(stderr, fmt, ap);
+		fputs (": ", stderr);
+	}
+	fputs(strerror(error), stderr);
+}
+
+void warnc(int error, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	vwarnc(error, fmt, ap);
+	va_end(ap);
+}
+
+_Noreturn void verrc(int status, int error, const char *fmt, va_list ap)
+{
+	vwarnc(error, fmt, ap);
+	exit(status);
+}
+
+_Noreturn void errc(int status, int error, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verrc(status, error, fmt, ap);
+	va_end(ap);
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-14  6:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-13  6:06 [RFC] Implement errc/warnc family of functions Isaac Dunham
2014-06-13  8:56 ` Justin Cormack
2014-06-13 16:33 ` Rich Felker
2014-06-14  2:33   ` [RFC] [v2] " Isaac Dunham
2014-06-14  6:34     ` writeonce

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).