gsasl-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS gsasl/gl


From: gsasl-commit
Subject: CVS gsasl/gl
Date: Fri, 19 Nov 2004 03:21:33 +0100

Update of /home/cvs/gsasl/gl
In directory dopio:/tmp/cvs-serv5420/gl

Modified Files:
        getaddrinfo.c getaddrinfo.h getopt.c getopt1.c getopt_.h 
        getopt_int.h progname.c progname.h 
Log Message:
Update.

--- /home/cvs/gsasl/gl/getaddrinfo.c    2004/09/19 10:21:02     1.2
+++ /home/cvs/gsasl/gl/getaddrinfo.c    2004/11/19 02:21:33     1.3
@@ -20,13 +20,40 @@
 # include <config.h>
 #endif
 
-#include <stdio.h>
-#include <gettext.h>
+/* Get calloc. */
+#include <stdlib.h>
+
+/* Get memcpy. */
+#include <string.h>
+
+/* Get struct hostent. */
+#include <netdb.h>
+
+#include <stdbool.h>
+
+#include "gettext.h"
 #define _(String) gettext (String)
 #define N_(String) String
 
 #include "getaddrinfo.h"
 
+static inline bool
+validate_family (int family)
+{
+  /* FIXME: Support more families. */
+#if HAVE_IPV4
+     if (family == PF_INET)
+       return true;
+#endif
+#if HAVE_IPV6
+     if (family == PF_INET6)
+       return true;
+#endif
+     if (family == PF_UNSPEC)
+       return true;
+     return false;
+}
+
 /* Translate name of a service location and/or a service name to set of
    socket addresses. */
 int
@@ -36,20 +63,15 @@
             struct addrinfo **restrict res)
 {
   struct addrinfo *tmp;
-  struct sockaddr sock;
-  struct sockaddr *sockp = &sock;
   struct servent *se;
   struct hostent *he;
+  size_t sinlen;
 
   if (hints && hints->ai_flags)
     /* FIXME: Support more flags. */
     return EAI_BADFLAGS;
 
-  if (hints &&
-      hints->ai_family != PF_UNSPEC &&
-      hints->ai_family != PF_INET &&
-      hints->ai_family != PF_INET6)
-    /* FIXME: Support more families. */
+  if (hints && !validate_family (hints->ai_family))
     return EAI_FAMILY;
 
   if (hints && hints->ai_socktype)
@@ -57,10 +79,9 @@
     return EAI_SOCKTYPE;
 
   if (hints &&
-      hints->ai_protocol != SOCK_STREAM &&
-      hints->ai_protocol != SOCK_DGRAM)
-      /* FIXME: Support other protocols. */
-    return EAI_SERVICE; /* FIXME: Better return code? */
+      hints->ai_protocol != SOCK_STREAM && hints->ai_protocol != SOCK_DGRAM)
+    /* FIXME: Support other protocols. */
+    return EAI_SERVICE;                /* FIXME: Better return code? */
 
   if (!nodename)
     /* FIXME: Support server bind mode. */
@@ -68,69 +89,90 @@
 
   if (servname)
     {
+      const char *proto =
+       (hints && hints->ai_protocol == SOCK_DGRAM) ? "udp" : "tcp";
+
       /* FIXME: Use getservbyname_r if available. */
-      se = getservbyname (servname,
-                         hints->ai_protocol == SOCK_DGRAM ? "udp" : "tcp");
+      se = getservbyname (servname, proto);
+
       if (!se)
        return EAI_SERVICE;
     }
 
   /* FIXME: Use gethostbyname_r if available. */
-  he = gethostbyname (connect_hostname);
+  he = gethostbyname (nodename);
   if (!he || he->h_addr_list[0] == NULL)
     return EAI_NONAME;
 
-  tmp = calloc (1, sizeof (*tmp));
+  switch (he->h_addrtype)
+    {
+#if HAVE_IPV6
+    case PF_INET6:
+      sinlen = sizeof (struct sockaddr_in6);
+      break;
+#endif
+
+#if HAVE_IPV4
+    case PF_INET:
+      sinlen = sizeof (struct sockaddr_in);
+      break;
+#endif
+
+    default:
+      return EAI_NODATA;
+    }
+
+  tmp = calloc (1, sizeof (*tmp) + sinlen);
   if (!tmp)
     return EAI_MEMORY;
 
-  tmp->ai_addr->sa_family = he->he_addrtype;
-
-  switch (tmp->ai_addr->sa_family)
+  switch (he->h_addrtype)
     {
+#if HAVE_IPV6
     case PF_INET6:
       {
-       struct sockaddr_in6 *sinp;
+       struct sockaddr_in6 *sinp = (void *) tmp + sizeof (*tmp);
 
-       sinp = calloc (1, sizeof (*sinp));
-       if (!sinp)
-         {
-           free (tmp);
-           return EAI_MEMORY;
-         }
+       if (se)
+         sinp->sin6_port = se->s_port;
 
-       sinp->sin_port = se->s_port;
-       memcpy (&sinp->sin_addr, he->h_addr_list[0], he->h_length);
+       if (he->h_length != sizeof (sinp->sin6_addr))
+         return EAI_SYSTEM; /* FIXME: Better return code?  Set errno? */
 
-       tmp->ai_addr = sinp;
-       tmp->ai_addrlen = sizeof (sin);
+       memcpy (&sinp->sin6_addr, he->h_addr_list[0], he->h_length);
+
+       tmp->ai_addr = (struct sockaddr *) sinp;
+       tmp->ai_addrlen = sinlen;
       }
       break;
+#endif
 
+#if HAVE_IPV4
     case PF_INET:
       {
-       struct sockaddr_in *sinp;
+       struct sockaddr_in *sinp = (void *) tmp + sizeof (*tmp);
+
+       if (se)
+         sinp->sin_port = se->s_port;
 
-       sinp = calloc (1, sizeof (*sinp));
-       if (!sinp)
-         {
-           free (tmp);
-           return EAI_MEMORY;
-         }
+       if (he->h_length != sizeof (sinp->sin_addr))
+         return EAI_SYSTEM; /* FIXME: Better return code?  Set errno? */
 
-       sinp->sin_port = se->s_port;
        memcpy (&sinp->sin_addr, he->h_addr_list[0], he->h_length);
 
-       tmp->ai_addr = sinp;
-       tmp->ai_addrlen = sizeof (sin);
+       tmp->ai_addr = (struct sockaddr *) sinp;
+       tmp->ai_addrlen = sinlen;
       }
       break;
+#endif
 
     default:
       free (tmp);
       return EAI_NODATA;
     }
 
+  tmp->ai_addr->sa_family = he->h_addrtype;
+
   /* FIXME: If more than one address, create linked list of addrinfo's. */
 
   *res = tmp;
@@ -151,35 +193,3 @@
       free (cur);
     }
 }
-
-static struct
-  {
-    int code;
-    const char *msg;
-  }
-values[] =
-  {
-    { EAI_ADDRFAMILY, N_("Address family for hostname not supported") },
-    { EAI_AGAIN, N_("Temporary failure in name resolution") },
-    { EAI_BADFLAGS, N_("Bad value for ai_flags") },
-    { EAI_FAIL, N_("Non-recoverable failure in name resolution") },
-    { EAI_FAMILY, N_("ai_family not supported") },
-    { EAI_MEMORY, N_("Memory allocation failure") },
-    { EAI_NODATA, N_("No address associated with hostname") },
-    { EAI_NONAME, N_("Name or service not known") },
-    { EAI_SERVICE, N_("Servname not supported for ai_socktype") },
-    { EAI_SOCKTYPE, N_("ai_socktype not supported") },
-    { EAI_SYSTEM, N_("System error") },
-  };
-
-/* Convert error return from getaddrinfo() to a string.  */
-const char *
-gai_strerror (int code)
-{
-  size_t i;
-  for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
-    if (values[i].code == code)
-      return _(values[i].msg);
-
-  return _("Unknown error");
-}
--- /home/cvs/gsasl/gl/getaddrinfo.h    2004/09/19 10:21:02     1.2
+++ /home/cvs/gsasl/gl/getaddrinfo.h    2004/11/19 02:21:33     1.3
@@ -16,7 +16,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-#ifndef        GETADDRINFO_H
+#ifndef GETADDRINFO_H
 # define GETADDRINFO_H
 
 /* Get getaddrinfo declarations, if available. */
@@ -63,6 +63,14 @@
 # define EAI_MEMORY      -10   /* Memory allocation failure.  */
 # define EAI_SYSTEM      -11   /* System error returned in `errno'.  */
 # define EAI_OVERFLOW    -12   /* Argument buffer overflow.  */
+# ifdef __USE_GNU
+#  define EAI_INPROGRESS  -100 /* Processing request in progress.  */
+#  define EAI_CANCELED   -101  /* Request canceled.  */
+#  define EAI_NOTCANCELED -102 /* Request not canceled.  */
+#  define EAI_ALLDONE    -103  /* All requests done.  */
+#  define EAI_INTR       -104  /* Interrupted by a signal.  */
+#  define EAI_IDN_ENCODE  -105 /* IDN encoding failed.  */
+# endif
 
 /* Translate name of a service location and/or a service name to set of
    socket addresses.  */
--- /home/cvs/gsasl/gl/getopt.c 2004/07/16 16:58:09     1.7
+++ /home/cvs/gsasl/gl/getopt.c 2004/11/19 02:21:33     1.8
@@ -3,7 +3,7 @@
    "Keep this file name-space clean" means, talk to address@hidden
    before changing it!
    Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004
-       Free Software Foundation, Inc.
+       Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
@@ -62,16 +62,16 @@
 # define attribute_hidden
 #endif
 
-/* This version of `getopt' appears to the caller like standard Unix `getopt'
-   but it behaves differently for the user, since it allows the user
-   to intersperse the options with the other arguments.
+/* Unlike standard Unix `getopt', functions like `getopt_long'
+   let the user intersperse the options with the other arguments.
 
-   As `getopt' works, it permutes the elements of ARGV so that,
+   As `getopt_long' works, it permutes the elements of ARGV so that,
    when it is done, all the options precede everything else.  Thus
    all application programs are extended to handle flexible argument order.
 
-   Setting the environment variable POSIXLY_CORRECT disables permutation.
-   Then the behavior is completely standard.
+   Using `getopt' or setting the environment variable POSIXLY_CORRECT
+   disables permutation.
+   Then the application's behavior is completely standard.
 
    GNU application programs can use a third alternative mode in which
    they can distinguish the relative order of options and other arguments.  */
@@ -250,8 +250,8 @@
 /* Initialize the internal data when the first call is made.  */
 
 static const char *
-_getopt_initialize (int argc, char *const *argv, const char *optstring,
-                   struct _getopt_data *d)
+_getopt_initialize (int argc, char **argv, const char *optstring,
+                   int posixly_correct, struct _getopt_data *d)
 {
   /* Start processing options with ARGV-element 1 (since ARGV-element 0
      is the program name); the sequence of previously skipped
@@ -261,7 +261,7 @@
 
   d->__nextchar = NULL;
 
-  d->__posixly_correct = !!getenv ("POSIXLY_CORRECT");
+  d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
 
   /* Determine how to handle the ordering of options and nonoptions.  */
 
@@ -355,10 +355,6 @@
    `flag' field is nonzero, the value of the option's `val' field
    if the `flag' field is zero.
 
-   The elements of ARGV aren't really const, because we permute them.
-   But we pretend they're const in the prototype to be compatible
-   with other systems.
-
    LONGOPTS is a vector of `struct option' terminated by an
    element containing a name which is zero.
 
@@ -367,12 +363,15 @@
    recent call.
 
    If LONG_ONLY is nonzero, '-' as well as '--' can introduce
-   long-named options.  */
+   long-named options.
+
+   If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT
+   environment variable were set.  */
 
 int
-_getopt_internal_r (int argc, char *const *argv, const char *optstring,
+_getopt_internal_r (int argc, char **argv, const char *optstring,
                    const struct option *longopts, int *longind,
-                   int long_only, struct _getopt_data *d)
+                   int long_only, int posixly_correct, struct _getopt_data *d)
 {
   int print_errors = d->opterr;
   if (optstring[0] == ':')
@@ -387,7 +386,8 @@
     {
       if (d->optind == 0)
        d->optind = 1;  /* Don't scan ARGV[0], the program name.  */
-      optstring = _getopt_initialize (argc, argv, optstring, d);
+      optstring = _getopt_initialize (argc, argv, optstring,
+                                     posixly_correct, d);
       d->__initialized = 1;
     }
 
@@ -1135,16 +1135,17 @@
 }
 
 int
-_getopt_internal (int argc, char *const *argv, const char *optstring,
-                 const struct option *longopts, int *longind, int long_only)
+_getopt_internal (int argc, char **argv, const char *optstring,
+                 const struct option *longopts, int *longind,
+                 int long_only, int posixly_correct)
 {
   int result;
 
   getopt_data.optind = optind;
   getopt_data.opterr = opterr;
 
-  result = _getopt_internal_r (argc, argv, optstring, longopts,
-                              longind, long_only, &getopt_data);
+  result = _getopt_internal_r (argc, argv, optstring, longopts, longind,
+                              long_only, posixly_correct, &getopt_data);
 
   optind = getopt_data.optind;
   optarg = getopt_data.optarg;
@@ -1153,13 +1154,19 @@
   return result;
 }
 
+/* glibc gets a LSB-compliant getopt.
+   Standalone applications get a POSIX-compliant getopt.  */
+#if _LIBC
+enum { POSIXLY_CORRECT = 0 };
+#else
+enum { POSIXLY_CORRECT = 1 };
+#endif
+
 int
 getopt (int argc, char *const *argv, const char *optstring)
 {
-  return _getopt_internal (argc, argv, optstring,
-                          (const struct option *) 0,
-                          (int *) 0,
-                          0);
+  return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0,
+                          POSIXLY_CORRECT);
 }
 
 
--- /home/cvs/gsasl/gl/getopt1.c        2004/07/16 16:58:09     1.7
+++ /home/cvs/gsasl/gl/getopt1.c        2004/11/19 02:21:33     1.8
@@ -41,19 +41,20 @@
 #endif
 
 int
-getopt_long (int argc, char *const *argv, const char *options,
+getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
             const struct option *long_options, int *opt_index)
 {
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+  return _getopt_internal (argc, (char **) argv, options, long_options,
+                          opt_index, 0, 0);
 }
 
 int
-_getopt_long_r (int argc, char *const *argv, const char *options,
+_getopt_long_r (int argc, char **argv, const char *options,
                const struct option *long_options, int *opt_index,
                struct _getopt_data *d)
 {
   return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-                            0, d);
+                            0, 0, d);
 }
 
 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -62,19 +63,21 @@
    instead.  */
 
 int
-getopt_long_only (int argc, char *const *argv, const char *options,
+getopt_long_only (int argc, char *__getopt_argv_const *argv,
+                 const char *options,
                  const struct option *long_options, int *opt_index)
 {
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
+  return _getopt_internal (argc, (char **) argv, options, long_options,
+                          opt_index, 1, 0);
 }
 
 int
-_getopt_long_only_r (int argc, char *const *argv, const char *options,
+_getopt_long_only_r (int argc, char **argv, const char *options,
                     const struct option *long_options, int *opt_index,
                     struct _getopt_data *d)
 {
   return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-                            1, d);
+                            1, 0, d);
 }
 
 
--- /home/cvs/gsasl/gl/getopt_.h        2004/07/02 08:26:24     1.1
+++ /home/cvs/gsasl/gl/getopt_.h        2004/11/19 02:21:33     1.2
@@ -23,6 +23,47 @@
 # define _GETOPT_H 1
 #endif
 
+/* Standalone applications should #define __GETOPT_PREFIX to an
+   identifier that prefixes the external functions and variables
+   defined in this header.  When this happens, include the
+   headers that might declare getopt so that they will not cause
+   confusion if included after this file.  Then systematically rename
+   identifiers so that they do not collide with the system functions
+   and variables.  Renaming avoids problems with some compilers and
+   linkers.  */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# include <stdlib.h>
+# include <stdio.h>
+# if HAVE_UNISTD_H
+#  include <unistd.h>
+# endif
+# undef getopt
+# undef getopt_long
+# undef getopt_long_only
+# undef optarg
+# undef opterr
+# undef optind
+# undef optopt
+# define getopt __GETOPT_PREFIX##getopt
+# define getopt_long __GETOPT_PREFIX##getopt_long
+# define getopt_long_only __GETOPT_PREFIX##getopt_long_only
+# define optarg __GETOPT_PREFIX##optarg
+# define opterr __GETOPT_PREFIX##opterr
+# define optind __GETOPT_PREFIX##optind
+# define optopt __GETOPT_PREFIX##optopt
+#endif
+
+/* Standalone applications get correct prototypes for getopt_long and
+   getopt_long_only; they declare "char **argv".  libc uses prototypes
+   with "char *const *argv" that are incorrect because getopt_long and
+   getopt_long_only can permute argv; this is required for backward
+   compatibility (e.g., for LSB 2.0.1).  */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# define __getopt_argv_const /* empty */
+#else
+# define __getopt_argv_const const
+#endif
+
 /* If __GNU_LIBRARY__ is not already defined, either we are being used
    standalone, or this is the first header included in the source file.
    If we are being used with glibc, we need to include <features.h>, but
@@ -89,7 +130,7 @@
    The field `has_arg' is:
    no_argument         (or 0) if the option does not take an argument,
    required_argument   (or 1) if the option requires an argument,
-   optional_argument   (or 2) if the option takes an optional argument.
+   optional_argument   (or 2) if the option takes an optional argument.
 
    If the field `flag' is not NULL, it points to a variable that is set
    to the value given in the field `val' when the option is found, but
@@ -144,22 +185,15 @@
    arguments to the option '\0'.  This behavior is specific to the GNU
    `getopt'.  */
 
-#ifdef __GNU_LIBRARY__
-/* Many other libraries have conflicting prototypes for getopt, with
-   differences in the consts, in stdlib.h.  To avoid compilation
-   errors, only prototype getopt for the GNU C library.  */
 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
        __THROW;
-#else /* not __GNU_LIBRARY__ */
-extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
 
 #ifndef __need_getopt
-extern int getopt_long (int ___argc, char *const *___argv,
+extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
                        const char *__shortopts,
                        const struct option *__longopts, int *__longind)
        __THROW;
-extern int getopt_long_only (int ___argc, char *const *___argv,
+extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
                             const char *__shortopts,
                             const struct option *__longopts, int *__longind)
        __THROW;
--- /home/cvs/gsasl/gl/getopt_int.h     2004/06/26 13:31:36     1.1
+++ /home/cvs/gsasl/gl/getopt_int.h     2004/11/19 02:21:33     1.2
@@ -20,10 +20,10 @@
 #ifndef _GETOPT_INT_H
 #define _GETOPT_INT_H  1
 
-extern int _getopt_internal (int ___argc, char *const *___argv,
+extern int _getopt_internal (int ___argc, char **___argv,
                             const char *__shortopts,
                             const struct option *__longopts, int *__longind,
-                            int __long_only);
+                            int __long_only, int __posixly_correct);
 
 
 /* Reentrant versions which can handle parsing multiple argument
@@ -64,7 +64,7 @@
      This is what Unix does.
      This mode of operation is selected by either setting the environment
      variable POSIXLY_CORRECT, or using `+' as the first character
-     of the list of option characters.
+     of the list of option characters, or by calling getopt.
 
      PERMUTE is the default.  We permute the contents of ARGV as we
      scan, so that eventually all the non-options are at the end.
@@ -87,7 +87,8 @@
       REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
     } __ordering;
 
-  /* If the POSIXLY_CORRECT environment variable is set.  */
+  /* If the POSIXLY_CORRECT environment variable is set
+     or getopt was called.  */
   int __posixly_correct;
 
 
@@ -110,17 +111,18 @@
    default values and to clear the initialization flag.  */
 #define _GETOPT_DATA_INITIALIZER       { 1, 1 }
 
-extern int _getopt_internal_r (int ___argc, char *const *___argv,
+extern int _getopt_internal_r (int ___argc, char **___argv,
                               const char *__shortopts,
                               const struct option *__longopts, int *__longind,
-                              int __long_only, struct _getopt_data *__data);
+                              int __long_only, int __posixly_correct,
+                              struct _getopt_data *__data);
 
-extern int _getopt_long_r (int ___argc, char *const *___argv,
+extern int _getopt_long_r (int ___argc, char **___argv,
                           const char *__shortopts,
                           const struct option *__longopts, int *__longind,
                           struct _getopt_data *__data);
 
-extern int _getopt_long_only_r (int ___argc, char *const *___argv,
+extern int _getopt_long_only_r (int ___argc, char **___argv,
                                const char *__shortopts,
                                const struct option *__longopts,
                                int *__longind,
--- /home/cvs/gsasl/gl/progname.c       2004/09/19 10:21:02     1.2
+++ /home/cvs/gsasl/gl/progname.c       2004/11/19 02:21:33     1.3
@@ -1,5 +1,5 @@
 /* Program name management.
-   Copyright (C) 2001-2004 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
    Written by Bruno Haible <address@hidden>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -51,16 +51,3 @@
     argv0 = base + 3;
   program_name = argv0;
 }
-
-/* Return short program name of the current executable, based on the
-   earlier call to set_program_name.  Return NULL if unknown.  The
-   short program name is computed by removing all directory names and
-   path separators. */
-const char *
-get_short_program_name (void)
-{
-  const char *slash = NULL;
-  if (program_name)
-    slash = strrchr (program_name, '/');
-  return slash != NULL ? slash + 1 : program_name;
-}
--- /home/cvs/gsasl/gl/progname.h       2004/09/29 00:03:47     1.4
+++ /home/cvs/gsasl/gl/progname.h       2004/11/19 02:21:33     1.5
@@ -35,12 +35,6 @@
 /* Set program_name, based on argv[0].  */
 extern void set_program_name (const char *argv0);
 
-/* Return short program name of the current executable, based on the
-   earlier call to set_program_name.  Return NULL if unknown.  The
-   short program name is computed by removing all directory names and
-   path separators. */
-extern const char *get_short_program_name (void);
-
 #if ENABLE_RELOCATABLE
 
 /* Set program_name, based on argv[0], and original installation prefix and





reply via email to

[Prev in Thread] Current Thread [Next in Thread]