This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc 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]

Re: Portability fix for argp/argp.h.


Expect more to come.

(If someone wonder why mapping __strndup to strndup help portability,
as strndup isn't universally available, here is an explanation: the
argp sources are to be used as a gnulib package, which define strndup
if it doesn't exist.  If the goal would be to make argp in libc truly
portable, without help from portability glue like the gnulib argp
package provide, a lot more fixes would be required.  I think it is
better to target for gnulib portability first, and leave
self-contained portability to later for someone who cares about it.
Self-contained portability would also pollute the source code further,
making it more unreadable, so there are even arguments against going
there.)

2003-07-10  Simon Josefsson  <jas@extundo.com>

	* argp/argp-help.c: Don't include malloc.h, some platforms
	complain and it doesn't appear to be used.
	[!__attribute]: Define to nothing.
	[!__strchrnul]: Define to strchrnul.
	[!__strndup]: Define to strndup.

	* argp/argp.h [!__attribute__]: Define to nothing.

	* argp/argp-fmtstream.h: Ditto.

Index: argp.h
===================================================================
RCS file: /cvs/glibc/libc/argp/argp.h,v
retrieving revision 1.25
diff -u -p -u -w -r1.25 argp.h
--- argp.h	12 Jun 2003 18:07:27 -0000	1.25
+++ argp.h	10 Jul 2003 09:55:13 -0000
@@ -36,6 +36,19 @@
 # define __THROW
 #endif
 
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
 #ifndef __error_t_defined
 typedef int error_t;
 # define __error_t_defined
Index: argp-fmtstream.h
===================================================================
RCS file: /cvs/glibc/libc/argp/argp-fmtstream.h,v
retrieving revision 1.4
diff -u -p -u -w -r1.4 argp-fmtstream.h
--- argp-fmtstream.h	6 Jul 2001 04:54:44 -0000	1.4
+++ argp-fmtstream.h	10 Jul 2003 09:56:31 -0000
@@ -34,6 +34,19 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
 #if    (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
     || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
 /* line_wrap_stream is available, so use that.  */
Index: argp-help.c
===================================================================
RCS file: /cvs/glibc/libc/argp/argp-help.c,v
retrieving revision 1.37
diff -u -p -u -w -r1.37 argp-help.c
--- argp-help.c	13 Jun 2003 20:38:13 -0000	1.37
+++ argp-help.c	10 Jul 2003 10:13:29 -0000
@@ -50,7 +50,6 @@ char *alloca ();
 #include <string.h>
 #include <assert.h>
 #include <stdarg.h>
-#include <malloc.h>
 #include <ctype.h>
 #ifdef USE_IN_LIBIO
 # include <wchar.h>
@@ -70,6 +69,24 @@ char *alloca ();
 # endif
 #endif
 
+#ifndef __attribute
+# define __attribute(xyz)     /* Ignore */
+#endif
+
+#ifndef __strchrnul
+# define __strchrnul strchrnul
+#endif
+
+#ifndef __strndup
+# define __strndup strndup
+#endif
+
+#ifndef _LIBC
+# if !HAVE_DECL_STRERROR
+char *strerror ();
+# endif
+#endif
+
 #include "argp.h"
 #include "argp-fmtstream.h"
 #include "argp-namefrob.h"
@@ -1813,13 +1830,21 @@ __argp_failure (const struct argp_state 
 #ifdef USE_IN_LIBIO
 	      if (_IO_fwide (stream, 0) > 0)
 		__fwprintf (stream, L": %s",
+#if defined _LIBC
 			    __strerror_r (errnum, buf, sizeof (buf)));
+#else
+			    __fwprintf (stream, L": %s", strerror (errnum));
+#endif
 	      else
 #endif
 		{
 		  putc_unlocked (':', stream);
 		  putc_unlocked (' ', stream);
+#if defined _LIBC
 		  fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
+#else
+		  fputs (strerror (errnum), stream);
+#endif
 		}
 	    }
 


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