]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update.
authorUlrich Drepper <drepper@redhat.com>
Thu, 2 Oct 2003 22:55:10 +0000 (22:55 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 2 Oct 2003 22:55:10 +0000 (22:55 +0000)
2003-08-22  Simon Josefsson  <jas@extundo.com>

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

* argp/argp-help.c: Don't include malloc.h, some platforms
complain and it doesn't appear to be used.
[!_LIBC && HAVE_STRERROR_R && !HAVE_DECL_STRERROR_R]: Declare
strerror_r.
[!_LIBC && !HAVE_STRERROR_R && !HAVE_DECL_STRERROR]: Declare
strerror.
(hol_entry_long_iterate): Change __attribute to __attribute__.
(_help, __argp_error, __argp_failure) [!_LIBC && (HAVE_FLOCKFILE
&& HAVE_FUNLOCKFILE)]: Protect call to flockfile and funlockfile.
(__argp_basename) [!_LIBC]: New. Taken from LSH, by Niels Möller,
modifed after comments from Ulrich Drepper.
(__argp_short_program_name): Ditto.
(__argp_state_help, __argp_error, __argp_failure): Use it.
(__argp_failure): Use strerror when necessary.

* argp/argp-namefrob.h (__flockfile, __funlockfile, __mempcpy)
(__strchrnul, __strerror_r, __strndup) [!_LIBC]: Remove __-prefix.
(clearerr_unlocked, feof_unlocked, ferror_unlocked)
(fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked)
(fread_unlocked, fwrite_unlocked, getc_unlocked, getchar_unlocked)
(putc_unlocked, putchar_unlocked) [!_LIBC && !HAVE_DECL_*]: Map to
non-unlocked functions.
[!_LIBC]: Add prototypes for __argp_basename and
__argp_short_program_name.

* argp/argp-parse.c (argp_default_parser): Only use
program_invocation{_short,}_name if declared.
(parser_init): Use __argp_short_program_name.

* argp/argp-xinl.c [_LIBC || HAVE_FEATURES_H]: Add CPP check for
'#include features.h'.

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

ChangeLog
argp/argp-fmtstream.h
argp/argp-help.c
argp/argp-namefrob.h
argp/argp-parse.c
argp/argp-xinl.c
argp/argp.h

index b52de0049f4c7d76954be79b0a9ee45b457b5378..dedba08a8de5e96032b28a7ffa95e78745d81fff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2003-08-22  Simon Josefsson  <jas@extundo.com>
+
+       * argp/argp-fmtstream.h [!__attribute__]: Define to nothing.
+
+       * argp/argp-help.c: Don't include malloc.h, some platforms
+       complain and it doesn't appear to be used.
+       [!_LIBC && HAVE_STRERROR_R && !HAVE_DECL_STRERROR_R]: Declare
+       strerror_r.
+       [!_LIBC && !HAVE_STRERROR_R && !HAVE_DECL_STRERROR]: Declare
+       strerror.
+       (hol_entry_long_iterate): Change __attribute to __attribute__.
+       (_help, __argp_error, __argp_failure) [!_LIBC && (HAVE_FLOCKFILE
+       && HAVE_FUNLOCKFILE)]: Protect call to flockfile and funlockfile.
+       (__argp_basename) [!_LIBC]: New. Taken from LSH, by Niels Möller,
+       modifed after comments from Ulrich Drepper.
+       (__argp_short_program_name): Ditto.
+       (__argp_state_help, __argp_error, __argp_failure): Use it.
+       (__argp_failure): Use strerror when necessary.
+
+       * argp/argp-namefrob.h (__flockfile, __funlockfile, __mempcpy)
+       (__strchrnul, __strerror_r, __strndup) [!_LIBC]: Remove __-prefix.
+       (clearerr_unlocked, feof_unlocked, ferror_unlocked)
+       (fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked)
+       (fread_unlocked, fwrite_unlocked, getc_unlocked, getchar_unlocked)
+       (putc_unlocked, putchar_unlocked) [!_LIBC && !HAVE_DECL_*]: Map to
+       non-unlocked functions.
+       [!_LIBC]: Add prototypes for __argp_basename and
+       __argp_short_program_name.
+
+       * argp/argp-parse.c (argp_default_parser): Only use
+       program_invocation{_short,}_name if declared.
+       (parser_init): Use __argp_short_program_name.
+
+       * argp/argp-xinl.c [_LIBC || HAVE_FEATURES_H]: Add CPP check for
+       '#include features.h'.
+
+       * argp/argp.h [!__attribute__]: Define to nothing.
+
 2003-09-26  Paolo Bonzini  <bonzini@gnu.org>
 
        * posix/regcomp.c (parse_sub_exp): Pass RE_CARET_ANCHORS_HERE
index 7a291e28c3284caa263de4f5eb827a8e6540c514..5d0d5eac92a783b8a48df5c3a677405ebac9fe22 100644 (file)
 #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) || __STRICT_ANSI__
+#  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) || __STRICT_ANSI__
+#  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 3a2cfb49365b2c5308accaaed277bd45e7d9ad0b..f39ce2a74fe2bd1108dd8c8bd20aeaa8ab76ce66 100644 (file)
@@ -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,18 @@ char *alloca ();
 # endif
 #endif
 
+#ifndef _LIBC
+# if HAVE_STRERROR_R
+#  if !HAVE_DECL_STRERROR_R
+char *strerror_r (int errnum, char *buf, size_t buflen);
+#  endif
+# else
+#  if !HAVE_DECL_STRERROR
+char *strerror (int errnum);
+#  endif
+# endif
+#endif
+
 #include "argp.h"
 #include "argp-fmtstream.h"
 #include "argp-namefrob.h"
@@ -552,7 +563,7 @@ hol_entry_short_iterate (const struct hol_entry *entry,
 }
 
 static inline int
-__attribute ((always_inline))
+__attribute__ ((always_inline))
 hol_entry_long_iterate (const struct hol_entry *entry,
                        int (*func)(const struct argp_option *opt,
                                    const struct argp_option *real,
@@ -1538,7 +1549,9 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
   if (! stream)
     return;
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
   __flockfile (stream);
+#endif
 
   if (! uparams.valid)
     fill_in_uparams (state);
@@ -1546,7 +1559,9 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
   fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
   if (! fs)
     {
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
       __funlockfile (stream);
+#endif
       return;
     }
 
@@ -1654,7 +1669,9 @@ Try `%s --help' or `%s --usage' for more information.\n"),
       anything = 1;
     }
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
   __funlockfile (stream);
+#endif
 
   if (hol)
     hol_free (hol);
@@ -1673,6 +1690,32 @@ void __argp_help (const struct argp *argp, FILE *stream,
 weak_alias (__argp_help, argp_help)
 #endif
 
+#ifndef _LIBC
+char *__argp_basename (char *name)
+{
+  char *short_name = strrchr (name, '/');
+  return short_name ? short_name + 1 : name;
+}
+#endif
+
+char *
+__argp_short_program_name (void)
+{
+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+  return program_invocation_short_name;
+#elif HAVE_DECL_PROGRAM_INVOCATION_NAME
+  return __argp_basename (program_invocation_name);
+#else
+  /* FIXME: What now? Miles suggests that it is better to use NULL,
+     but currently the value is passed on directly to fputs_unlocked,
+     so that requires more changes. */
+#if __GNUC__
+# warning No reasonable value to return
+#endif /* __GNUC__ */
+  return "";
+#endif
+}
+
 /* Output, if appropriate, a usage message for STATE to STREAM.  FLAGS are
    from the set ARGP_HELP_*.  */
 void
@@ -1684,7 +1727,7 @@ __argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
        flags |= ARGP_HELP_LONG_ONLY;
 
       _help (state ? state->root_argp : 0, state, stream, flags,
-            state ? state->name : program_invocation_short_name);
+            state ? state->name : __argp_short_program_name ());
 
       if (!state || ! (state->flags & ARGP_NO_EXIT))
        {
@@ -1713,7 +1756,9 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
        {
          va_list ap;
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __flockfile (stream);
+#endif
 
          va_start (ap, fmt);
 
@@ -1725,7 +1770,7 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
              __asprintf (&buf, fmt, ap);
 
              __fwprintf (stream, L"%s: %s\n",
-                         state ? state->name : program_invocation_short_name,
+                         state ? state->name : __argp_short_program_name (),
                          buf);
 
              free (buf);
@@ -1734,7 +1779,7 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 #endif
            {
              fputs_unlocked (state
-                             ? state->name : program_invocation_short_name,
+                             ? state->name : __argp_short_program_name (),
                              stream);
              putc_unlocked (':', stream);
              putc_unlocked (' ', stream);
@@ -1748,7 +1793,9 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 
          va_end (ap);
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __funlockfile (stream);
+#endif
        }
     }
 }
@@ -1774,16 +1821,18 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 
       if (stream)
        {
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __flockfile (stream);
+#endif
 
 #ifdef USE_IN_LIBIO
          if (_IO_fwide (stream, 0) > 0)
            __fwprintf (stream, L"%s",
-                       state ? state->name : program_invocation_short_name);
+                       state ? state->name : __argp_short_program_name ());
          else
 #endif
            fputs_unlocked (state
-                           ? state->name : program_invocation_short_name,
+                           ? state->name : __argp_short_program_name (),
                            stream);
 
          if (fmt)
@@ -1827,7 +1876,11 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
                {
                  putc_unlocked (':', stream);
                  putc_unlocked (' ', stream);
+#if defined _LIBC || defined HAVE_STRERROR_R
                  fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
+#else
+                 fputs (strerror (errnum), stream);
+#endif
                }
            }
 
@@ -1838,7 +1891,9 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 #endif
            putc_unlocked ('\n', stream);
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __funlockfile (stream);
+#endif
 
          if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
            exit (status);
index 668f35d0d08c0f150537995de0d186a146a4ff3a..395d9b6dd820519b9a63d1480510b5462b19f1db 100644 (file)
 #define __argp_fmtstream_wmargin argp_fmtstream_wmargin
 
 /* normal libc functions we call */
+#undef __flockfile
+#define __flockfile flockfile
+#undef __funlockfile
+#define __funlockfile funlockfile
+#undef __mempcpy
+#define __mempcpy mempcpy
 #undef __sleep
 #define __sleep sleep
 #undef __strcasecmp
 #define __strcasecmp strcasecmp
+#undef __strchrnul
+#define __strchrnul strchrnul
+#undef __strerror_r
+#define __strerror_r strerror_r
+#undef __strndup
+#define __strndup strndup
 #undef __vsnprintf
 #define __vsnprintf vsnprintf
 
+#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
+# define clearerr_unlocked(x) clearerr (x)
+#endif
+#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
+# define feof_unlocked(x) feof (x)
+# endif
+#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
+# define ferror_unlocked(x) ferror (x)
+# endif
+#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
+# define fflush_unlocked(x) fflush (x)
+# endif
+#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
+# define fgets_unlocked(x,y,z) fgets (x,y,z)
+# endif
+#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED
+# define fputc_unlocked(x,y) fputc (x,y)
+# endif
+#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
+# define fputs_unlocked(x,y) fputs (x,y)
+# endif
+#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
+# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
+# endif
+#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
+# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
+# endif
+#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED
+# define getc_unlocked(x) getc (x)
+# endif
+#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED
+#  define getchar_unlocked() getchar ()
+# endif
+#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED
+# define putc_unlocked(x,y) putc (x,y)
+# endif
+#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED
+# define putchar_unlocked(x) putchar (x)
+# endif
+
+extern char *__argp_basename (char *name);
+extern char *__argp_short_program_name (void);
+
 #endif /* !_LIBC */
 
 #ifndef __set_errno
index 6d5f08cf83ccdf7e1f3f0a4c6ce7f9fa4347c614..0b619db0f305db91a39ea37f8c1d8e1d43488cff 100644 (file)
@@ -119,24 +119,28 @@ argp_default_parser (int key, char *arg, struct argp_state *state)
       break;
 
     case OPT_PROGNAME:         /* Set the program name.  */
+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
       program_invocation_name = arg;
-
+#endif
       /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
         __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
         to be that, so we have to be a bit careful here.]  */
-      arg = strrchr (arg, '/');
-      if (arg)
-       program_invocation_short_name = arg + 1;
-      else
-       program_invocation_short_name = program_invocation_name;
 
       /* Update what we use for messages.  */
-      state->name = program_invocation_short_name;
+      state->name = strrchr (arg, '/');
+      if (state->name)
+       state->name++;
+      else
+       state->name = arg;
+
+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+      program_invocation_short_name = state->name;
+#endif
 
       if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
          == ARGP_PARSE_ARGV0)
        /* Update what getopt uses too.  */
-       state->argv[0] = program_invocation_name;
+       state->argv[0] = arg;
 
       break;
 
@@ -599,7 +603,7 @@ parser_init (struct parser *parser, const struct argp *argp,
       parser->state.name = short_name ? short_name + 1 : argv[0];
     }
   else
-    parser->state.name = program_invocation_short_name;
+    parser->state.name = __argp_short_program_name ();
 
   return 0;
 }
index 3710f6f493202839ec65b3d8d12d4b2ef934e422..2431093ea3a533b6021f58ff1a141b058076f07e 100644 (file)
@@ -22,7 +22,9 @@
 #include <config.h>
 #endif
 
-#include <features.h>
+#if defined _LIBC || defined HAVE_FEATURES_H
+# include <features.h>
+#endif
 
 #ifndef __USE_EXTERN_INLINES
 # define __USE_EXTERN_INLINES  1
index 7d2dca2a6160783461af6a94cd8af02792b37bb6..cb2f85aee7b812c2807cdd4435f2f6891e0bd8bd 100644 (file)
 # define __THROW
 #endif
 
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  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) || __STRICT_ANSI__
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
 #ifndef __error_t_defined
 typedef int error_t;
 # define __error_t_defined