This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] Support %m in printf functions
- From: "Yaakov (Cygwin/X)" <yselkowitz at users dot sourceforge dot net>
- To: newlib <newlib at sources dot redhat dot com>
- Date: Sun, 01 Jan 2012 11:59:06 -0600
- Subject: [PATCH] Support %m in printf functions
This patch adds support for the "%m" conversion specifier in the printf
and wprintf functions, a GNU extension:
http://www.kernel.org/doc/man-pages/online/pages/man3/printf.3.html
Patch and STC attached.
Yaakov
Cygwin/X
2011-12-31 Yaakov Selkowitz <yselkowitz@...>
* libc/stdio/vfprintf.c (_VFPRINTF_R): Handle 'm' conversion specifier.
* libc/stdio/vfwprintf.c (_VFWPRINTF_R): Ditto.
Index: libc/stdio/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.79
diff -u -p -r1.79 vfprintf.c
--- libc/stdio/vfprintf.c 15 Feb 2010 16:10:28 -0000 1.79
+++ libc/stdio/vfprintf.c 1 Jan 2012 02:14:32 -0000
@@ -1225,6 +1225,10 @@ reswitch: switch (ch) {
sign = '-';
break;
#endif /* FLOATING_POINT */
+ case 'm': /* extension */
+ cp = _strerror_r (data, data->_errno, 0, NULL);
+ flags &= ~LONGINT;
+ goto string;
case 'n':
#ifndef _NO_LONGLONG
if (flags & QUADINT)
@@ -1272,8 +1276,8 @@ reswitch: switch (ch) {
#ifdef _WANT_IO_C99_FORMATS
case 'S':
#endif
- sign = '\0';
cp = GET_ARG (N, ap, char_ptr_t);
+string: sign = '\0';
#ifndef __OPTIMIZE_SIZE__
/* Behavior is undefined if the user passed a
NULL string when precision is not 0.
Index: libc/stdio/vfwprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfwprintf.c,v
retrieving revision 1.6
diff -u -p -r1.6 vfwprintf.c
--- libc/stdio/vfwprintf.c 15 Jul 2011 17:20:16 -0000 1.6
+++ libc/stdio/vfwprintf.c 1 Jan 2012 02:14:33 -0000
@@ -1074,6 +1074,10 @@ reswitch: switch (ch) {
sign = L'-';
break;
#endif /* FLOATING_POINT */
+ case L'm': /* GNU extension */
+ cp = (wchar_t *) _strerror_r (data, data->_errno, 0, NULL);
+ flags &= ~LONGINT;
+ goto string;
case L'n':
#ifndef _NO_LONGLONG
if (flags & QUADINT)
@@ -1118,8 +1122,8 @@ reswitch: switch (ch) {
#ifdef _WANT_IO_C99_FORMATS
case L'S': /* POSIX extension */
#endif
- sign = '\0';
cp = GET_ARG (N, ap, wchar_ptr_t);
+string: sign = '\0';
#ifndef __OPTIMIZE_SIZE__
/* Behavior is undefined if the user passed a
NULL string when precision is not 0.
@@ -1132,7 +1136,7 @@ reswitch: switch (ch) {
else
#endif /* __OPTIMIZE_SIZE__ */
#ifdef _MB_CAPABLE
- if (ch == L's' && !(flags & LONGINT)) {
+ if (ch != L'S' && !(flags & LONGINT)) {
char *arg = (char *) cp;
size_t insize = 0, nchars = 0, nconv = 0;
mbstate_t ps;
//@pragma CCOD:script no
#include <math.h>
#include <stdio.h>
#include <wchar.h>
int
main (void)
{
double d;
printf("%m\n");
d = sqrt (-1); /* EDOM */
wprintf(L"%m\n");
return 0;
}