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 v2] Support %m in printf functions


On Sun, 2012-01-01 at 11:59 -0600, Yaakov (Cygwin/X) wrote:
> 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

Thank you all for the comments.  The attached revised patch and STC
should take them into account.

The remaining issue is that of gating, specifically exactly how to do
so.  For the moment I'm using __CYGWIN__ until some agreement can be
reached.


Yaakov
Cygwin/X

2012-01-??  Yaakov Selkowitz  <yselkowitz@...>

	* libc/stdio/sprintf.c: Document 'm' conversion specifier.
	* libc/stdio/swprintf.c: Ditto.
	* libc/stdio/vfprintf.c (_VFPRINTF_R) [__CYGWIN__]: Handle 'm'
	conversion specifier.
	* libc/stdio/vfwprintf.c (_VFWPRINTF_R) [__CYGWIN__]: Ditto.

Index: libc/stdio/sprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/sprintf.c,v
retrieving revision 1.14
diff -u -p -r1.14 sprintf.c
--- libc/stdio/sprintf.c	12 Mar 2009 10:27:10 -0000	1.14
+++ libc/stdio/sprintf.c	6 Jan 2012 06:27:49 -0000
@@ -518,6 +518,10 @@ DESCRIPTION
 			implementation is similar to <<%#tx>>), except
 			that <<0x>> appears even for the NULL pointer.
 
+		o m
+			Prints the output of <<strerror(errno)>>; no
+			argument is required.  A GNU extension.
+
 		o-
 	O-
 
Index: libc/stdio/swprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/swprintf.c,v
retrieving revision 1.2
diff -u -p -r1.2 swprintf.c
--- libc/stdio/swprintf.c	12 Mar 2009 10:27:10 -0000	1.2
+++ libc/stdio/swprintf.c	6 Jan 2012 06:27:49 -0000
@@ -498,6 +498,10 @@ DESCRIPTION
 			implementation is similar to <<%#tx>>), except
 			that <<0x>> appears even for the NULL pointer.
 
+		o m
+			Prints the output of <<strerror(errno)>>; no
+			argument is required.  A GNU extension.
+
 		o-
 	O-
 
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	6 Jan 2012 06:27:49 -0000
@@ -1225,6 +1225,15 @@ reswitch:	switch (ch) {
 				sign = '-';
 			break;
 #endif /* FLOATING_POINT */
+#if defined(__CYGWIN__)
+		case 'm':  /* extension */
+			{
+				int dummy;
+				cp = _strerror_r (data, data->_errno, 1, &dummy);
+			}
+			flags &= ~LONGINT;
+			goto string;
+#endif
 		case 'n':
 #ifndef _NO_LONGLONG
 			if (flags & QUADINT)
@@ -1272,8 +1281,11 @@ reswitch:	switch (ch) {
 #ifdef _WANT_IO_C99_FORMATS
 		case 'S':
 #endif
-			sign = '\0';
 			cp = GET_ARG (N, ap, char_ptr_t);
+#if defined(__CYGWIN__)
+string:
+#endif
+			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	6 Jan 2012 06:27:49 -0000
@@ -1074,6 +1074,15 @@ reswitch:	switch (ch) {
 				sign = L'-';
 			break;
 #endif /* FLOATING_POINT */
+#if defined(__CYGWIN__)
+		case L'm':  /* GNU extension */
+			{
+				int dummy;
+				cp = (wchar_t *) _strerror_r (data, data->_errno, 1, &dummy);
+			}
+			flags &= ~LONGINT;
+			goto string;
+#endif
 		case L'n':
 #ifndef _NO_LONGLONG
 			if (flags & QUADINT)
@@ -1118,8 +1127,11 @@ reswitch:	switch (ch) {
 #ifdef _WANT_IO_C99_FORMATS
 		case L'S':	/* POSIX extension */
 #endif
-			sign = '\0';
 			cp = GET_ARG (N, ap, wchar_ptr_t);
+#if defined(__CYGWIN__)
+string:
+#endif
+			sign = '\0';
 #ifndef __OPTIMIZE_SIZE__
 			/* Behavior is undefined if the user passed a
 			   NULL string when precision is not 0.
@@ -1132,7 +1144,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 <errno.h>
#include <stdio.h>
#include <wchar.h>

int
main (void)
{
  printf("%m, %m\n");
  errno++;
  wprintf(L"%m\n");
  errno++;
  fprintf(stderr, "%20.10m\n");
  return 0;
}

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