This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] stdio: Add %m


This patch to newlib adds the %m format, which outputs
strerror(errno). This format is a glibc extension. I'm not usually a
champion of non-standard extensions to any libc. However, this
particular extension is used fairly widely and is mostly non-invasive.

In particular, busybox uses %m and the maintainers will not accept
patches converting this format to %s and strerror(errno) due to the
latter taking more space by making, typically, two additional function
calls -- one to __errno_location and one to strerror.

Cheers,
Shaun

2006-06-05 Shaun Jackman <sjackman@gmail.com>

	* newlib/libc/stdio/vfprintf.c (_vfprintf_r, _vfiprintf_r): Add
	the %m format, which outputs strerror(errno). This format is a
	glibc extension.

Index: newlib/libc/stdio/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.43
diff -u -r1.43 vfprintf.c
--- newlib/libc/stdio/vfprintf.c	28 Oct 2005 21:38:59 -0000	1.43
+++ newlib/libc/stdio/vfprintf.c	5 Jun 2006 16:34:50 -0000
@@ -905,6 +905,10 @@
				sign = '-';
			break;
#endif /* FLOATING_POINT */
+		case 'm': /* glibc extension */
+			cp = strerror(errno);
+			size = strlen(cp);
+			break;
		case 'n':
#ifndef _NO_LONGLONG
			if (flags & QUADINT)

Attachment: newlib-vfprintf-m.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]