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

* Re: [RFC] Implement errc/warnc family of functions
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Justin Cormack @ 2014-06-13  8:56 UTC (permalink / raw)
  To: musl

On Fri, Jun 13, 2014 at 7:06 AM, Isaac Dunham <ibid.ag@gmail.com> wrote:
> I was trying to build netbsd sed, and it needed errc.
> So I wrote an errc implementation.

NetBSD does not have errc any more, and sed is required to be POSIX
(at least) compatible as it is used in the build process, and you can
cross build NetBSD on pretty much any OS (including Musl, I test that)

The errc definition is provided by tools/compat in the source tree,
which uses the errc.c file which is under libc in the source tree but
is not actually built as part of libc any more.

Justin


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

* Re: [RFC] Implement errc/warnc family of functions
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Rich Felker @ 2014-06-13 16:33 UTC (permalink / raw)
  To: musl

On Thu, Jun 12, 2014 at 11:06:23PM -0700, Isaac Dunham wrote:
> I was trying to build netbsd sed, and it needed errc.
> So I wrote an errc implementation.

There was another patch for this about a month ago; look back and see
the thread. I'm not opposed to adding it as long as we can minimize
the code duplication between these ugly functions (but they're pretty
small anyway).

Rich


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

* [RFC] [v2] Implement errc/warnc family of functions
  2014-06-13 16:33 ` Rich Felker
@ 2014-06-14  2:33   ` Isaac Dunham
  2014-06-14  6:34     ` writeonce
  0 siblings, 1 reply; 5+ messages in thread
From: Isaac Dunham @ 2014-06-14  2:33 UTC (permalink / raw)
  To: musl

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

On Fri, Jun 13, 2014 at 12:33:23PM -0400, Rich Felker wrote:
> On Thu, Jun 12, 2014 at 11:06:23PM -0700, Isaac Dunham wrote:
> > I was trying to build netbsd sed, and it needed errc.
> > So I wrote an errc implementation.
> 
> There was another patch for this about a month ago; look back and see
> the thread. I'm not opposed to adding it as long as we can minimize
> the code duplication between these ugly functions (but they're pretty
> small anyway).
That was actually how this came to my attention at first; however, the
implementation you refer to was nonsense, since vwarnx does *not* have the
prototype
void vwarnx(int, const char *, va_list);

I'm not sure whether to go for adding it or not, since apparently netbsd
doesn't have it in libc.
I've also removed it from my local version of sed, andd am half-tempted to
go ahead and use POSIX "formatted error messages", a.k.a. fmtmsg() ;)

But if it's going in,
vwarn(fmt, ap);
is supposed to be equivalent to 
vwarnc(errno, fmt, ap);

So I could easily shrink that part.
I'm sending a second version, because it's trivial to fix.

HTH,
Isaac Dunham

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

diff --git a/include/err.h b/include/err.h
index 9f5cb6b..3dffbae 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, const char *, ...);
+void vwarnc(int, const char *, va_list);
 
 _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, int, const char *, ...);
+_Noreturn void verrc(int, int, const char *, va_list);
 
 #ifdef __cplusplus
 }
diff --git a/src/legacy/err.c b/src/legacy/err.c
index 0d6ab52..a7e1bdf 100644
--- a/src/legacy/err.c
+++ b/src/legacy/err.c
@@ -1,18 +1,26 @@
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 
 extern char *__progname;
 
-void vwarn(const char *fmt, va_list ap)
+void vwarnc(int error, const char *fmt, va_list ap)
 {
 	fprintf (stderr, "%s: ", __progname);
 	if (fmt) {
 		vfprintf(stderr, fmt, ap);
 		fputs (": ", stderr);
 	}
-	perror(0);
+	fputs(strerror(error), stderr);
+	fputc('\n', stderr);
+}
+
+void vwarn(const char *fmt, va_list ap)
+{
+	vwarnc(errno, fmt, ap);
 }
 
 void vwarnx(const char *fmt, va_list ap)
@@ -22,6 +30,12 @@ void vwarnx(const char *fmt, va_list ap)
 	putc('\n', stderr);
 }
 
+_Noreturn void verrc(int status, int error, const char *fmt, va_list ap)
+{
+	vwarnc(error, fmt, ap);
+	exit(status);
+}
+
 _Noreturn void verr(int status, const char *fmt, va_list ap)
 {
 	vwarn(fmt, ap);
@@ -34,6 +48,14 @@ _Noreturn void verrx(int status, const char *fmt, va_list ap)
 	exit(status);
 }
 
+void warnc(int error, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	vwarnc(error, fmt, ap);
+	va_end(ap);
+}
+
 void warn(const char *fmt, ...)
 {
 	va_list ap;
@@ -50,6 +72,14 @@ void warnx(const char *fmt, ...)
 	va_end(ap);
 }
 
+_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);
+}
+
 _Noreturn void err(int status, const char *fmt, ...)
 {
 	va_list ap;

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

* Re: [RFC] [v2] Implement errc/warnc family of functions
  2014-06-14  2:33   ` [RFC] [v2] " Isaac Dunham
@ 2014-06-14  6:34     ` writeonce
  0 siblings, 0 replies; 5+ messages in thread
From: writeonce @ 2014-06-14  6:34 UTC (permalink / raw)
  To: musl

On 06/13/2014 10:33 PM, Isaac Dunham wrote:
> On Fri, Jun 13, 2014 at 12:33:23PM -0400, Rich Felker wrote:
>> On Thu, Jun 12, 2014 at 11:06:23PM -0700, Isaac Dunham wrote:
>>> I was trying to build netbsd sed, and it needed errc.
>>> So I wrote an errc implementation.
>> There was another patch for this about a month ago; look back and see
>> the thread. I'm not opposed to adding it as long as we can minimize
>> the code duplication between these ugly functions (but they're pretty
>> small anyway).
> That was actually how this came to my attention at first; however, the
> implementation you refer to was nonsense, since vwarnx does *not* have the
> prototype
> void vwarnx(int, const char *, va_list);
Yes, that was a typo that persisted throughout the thread.  It should 
have read 'vwarnc'.
zg
>
> I'm not sure whether to go for adding it or not, since apparently netbsd
> doesn't have it in libc.
> I've also removed it from my local version of sed, andd am half-tempted to
> go ahead and use POSIX "formatted error messages", a.k.a. fmtmsg() ;)
>
> But if it's going in,
> vwarn(fmt, ap);
> is supposed to be equivalent to
> vwarnc(errno, fmt, ap);
>
> So I could easily shrink that part.
> I'm sending a second version, because it's trivial to fix.
>
> HTH,
> Isaac Dunham



^ 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).