]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fri Jun 28 02:41:08 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> cvs/libc-960628
authorRoland McGrath <roland@gnu.org>
Fri, 28 Jun 1996 08:56:59 +0000 (08:56 +0000)
committerRoland McGrath <roland@gnu.org>
Fri, 28 Jun 1996 08:56:59 +0000 (08:56 +0000)
* nss/Makefile (databases): New variable.
(routines, libnss_files-routines): Use it.
(subdir-dirs): Compute from $(services).

* sysdeps/unix/sysv/linux/syscalls.list (create_module, delete_module,
init_module, klogctl): Use EXTRA in the "caller" column so these get
added to unix-extra-syscalls and thus compiled in misc.

* string/Makefile (routines): Add strndup.
* string/strndup.c: New file.
* string/string.h: Declare strndup.
(strndupa): New macro.

* string/string.h: Declare __strdup.
* string/strdup.c: Deansideclized.  Define __ name and weak alias.

* string/string.h: Don't define memccpy as macro for [__OPTIMIZE__].

Thu Jun 27 23:43:22 1996  Richard Henderson  <rth@tamu.edu>

* sysdeps/alpha/dl-machine.h (elf_machine_rela):  The Alpha's
address-of operation and plt format conspire to require all
dynamic relocs to be resolved to actual symbols not plt entries.

Thu Jun 27 02:49:28 1996  Ulrich Drepper  <drepper@cygnus.com>

* catgets/gencat.c: Add casts to avoid signed<->unsigned warnings.

* grp/initgroups.c (initgroups): De-ansi-fy.
Move declaration of NGROUPS and GROUPS outside #if so that
the code compiles for NGROUPS_MAX != 0.

* inet/Makefile (headers): Add netinet/ether.h and netinet/if_ether.h.
(routines): Add ether_aton, ether_aton_r, ether_hton, ether_line,
ether_ntoa, ether_ntoa_r, and ether_ntoh.
* inet/ether_aton.c, inet/ether_aton_r.c, inet/ether_hton.c,
inet/ether_line.c, inet/ether_ntoa.c, inet/ether_ntoa_r.c,
inet/ether_ntoh.c: New files.  Implementation of functions to
handle Ethernet address to host mapping.
* inet/netinet/ether.h: New file.  Declare ether_* functions.
* netinet/ether.h: Wrapper around inet/netinet/ether.h for glibc
compilation.
* nss/ethers-lookup.c: New file.  Lookup function for ethers database.
* nss/Makefile (routines): Add ethers-lookup.
(libnss_files-routines): Add files-ethers.

* nss/getXXent_r.c: Don't define set*ent and end*ent function
with _r suffix.

* nss/nss_files/files-XXX.c (internal_endent): Don't reset
KEEP_STREAM every time called.
(_nss_files_end): Reset KEEP_STREAM here instead.
(internal_getent): If STREAM == NULL try to open instead of
signalling error.
Use cast to prevent warning.
Terminate read line in case the buffer is too small.

* nss/nss_files/files-ethers.c: New file.  Implementation of
Ethernet adress<->hostname lookup through files interface.

* stdlib/mbstowcs.c: Define based on mbsrtowcs().
* stdlib/mbtowc.c: Define based on mbrtowc().
* stdlib/wcstombs.c: Define based on wcsrtombs().
* stdlib/wctomb.c: Define based on wcrtomb().

* sunrpc/xdr.c (xdr_u_int): Avoid bogus call to
unexpected_sizes_in_xdr_u_int.

* sysdeps/generic/netinet/if_ether.h: New file.  Generic declaration
of `struct ether_addr'.
* sysdeps/unix/sysv/linux/netinet/if_ether.h: New file.  Linux specific
declaration of `struct ether_addr'.

* wcsmbs/mbrtowc.c: Handle case where argument PS is NULL.
* wcsmbs/mbsrtowcs.c: Ditto.
* wcsmbs/wcrtomb.c: Ditto.
* wcsmbs/wcsrtombs.c: Ditto.

* wcsmbs/mbsinit.c: Prepare for PS being NULL.

36 files changed:
ChangeLog
catgets/gencat.c
grp/initgroups.c
inet/Makefile
inet/ether_aton.c [new file with mode: 0644]
inet/ether_aton_r.c [new file with mode: 0644]
inet/ether_hton.c [new file with mode: 0644]
inet/ether_line.c [new file with mode: 0644]
inet/ether_ntoa.c [new file with mode: 0644]
inet/ether_ntoa_r.c [new file with mode: 0644]
inet/ether_ntoh.c [new file with mode: 0644]
inet/netinet/ether.h [new file with mode: 0644]
netinet/ether.h [new file with mode: 0644]
nss/Makefile
nss/ethers-lookup.c [new file with mode: 0644]
nss/getXXent_r.c
nss/nss_files/files-XXX.c
nss/nss_files/files-ethers.c [new file with mode: 0644]
stdlib/mbstowcs.c
stdlib/mbtowc.c
stdlib/wcstombs.c
stdlib/wctomb.c
string/Makefile
string/strdup.c
string/string.h
string/strndup.c [new file with mode: 0644]
sunrpc/xdr.c
sysdeps/alpha/dl-machine.h
sysdeps/generic/netinet/if_ether.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/netinet/if_ether.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/syscalls.list
wcsmbs/mbrtowc.c
wcsmbs/mbsinit.c
wcsmbs/mbsrtowcs.c
wcsmbs/wcrtomb.c
wcsmbs/wcsrtombs.c

index 87660835acb3d0c3968973a36a2dfd4fb7417d6e..d3ad0e0e4b8ee4a2415adb27e0d750e3b1775a81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,85 @@
+Fri Jun 28 02:41:08 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>
+
+       * nss/Makefile (databases): New variable.
+       (routines, libnss_files-routines): Use it.
+       (subdir-dirs): Compute from $(services).
+
+       * sysdeps/unix/sysv/linux/syscalls.list (create_module, delete_module,
+       init_module, klogctl): Use EXTRA in the "caller" column so these get
+       added to unix-extra-syscalls and thus compiled in misc.
+
+       * string/Makefile (routines): Add strndup.
+       * string/strndup.c: New file.
+       * string/string.h: Declare strndup.
+       (strndupa): New macro.
+
+       * string/string.h: Declare __strdup.
+       * string/strdup.c: Deansideclized.  Define __ name and weak alias.
+
+       * string/string.h: Don't define memccpy as macro for [__OPTIMIZE__].
+
+Thu Jun 27 23:43:22 1996  Richard Henderson  <rth@tamu.edu>
+
+       * sysdeps/alpha/dl-machine.h (elf_machine_rela):  The Alpha's
+       address-of operation and plt format conspire to require all
+       dynamic relocs to be resolved to actual symbols not plt entries.
+
+Thu Jun 27 02:49:28 1996  Ulrich Drepper  <drepper@cygnus.com>
+
+       * catgets/gencat.c: Add casts to avoid signed<->unsigned warnings.
+
+       * grp/initgroups.c (initgroups): De-ansi-fy.
+       Move declaration of NGROUPS and GROUPS outside #if so that
+       the code compiles for NGROUPS_MAX != 0.
+
+       * inet/Makefile (headers): Add netinet/ether.h and netinet/if_ether.h.
+       (routines): Add ether_aton, ether_aton_r, ether_hton, ether_line,
+       ether_ntoa, ether_ntoa_r, and ether_ntoh.
+       * inet/ether_aton.c, inet/ether_aton_r.c, inet/ether_hton.c,
+       inet/ether_line.c, inet/ether_ntoa.c, inet/ether_ntoa_r.c,
+       inet/ether_ntoh.c: New files.  Implementation of functions to
+       handle Ethernet address to host mapping.
+       * inet/netinet/ether.h: New file.  Declare ether_* functions.
+       * netinet/ether.h: Wrapper around inet/netinet/ether.h for glibc
+       compilation.
+       * nss/ethers-lookup.c: New file.  Lookup function for ethers database.
+       * nss/Makefile (routines): Add ethers-lookup.
+       (libnss_files-routines): Add files-ethers.
+
+       * nss/getXXent_r.c: Don't define set*ent and end*ent function
+       with _r suffix.
+
+       * nss/nss_files/files-XXX.c (internal_endent): Don't reset
+       KEEP_STREAM every time called.
+       (_nss_files_end): Reset KEEP_STREAM here instead.
+       (internal_getent): If STREAM == NULL try to open instead of
+       signalling error.
+       Use cast to prevent warning.
+       Terminate read line in case the buffer is too small.
+
+       * nss/nss_files/files-ethers.c: New file.  Implementation of
+       Ethernet adress<->hostname lookup through files interface.
+
+       * stdlib/mbstowcs.c: Define based on mbsrtowcs().
+       * stdlib/mbtowc.c: Define based on mbrtowc().
+       * stdlib/wcstombs.c: Define based on wcsrtombs().
+       * stdlib/wctomb.c: Define based on wcrtomb().
+
+       * sunrpc/xdr.c (xdr_u_int): Avoid bogus call to
+       unexpected_sizes_in_xdr_u_int.
+
+       * sysdeps/generic/netinet/if_ether.h: New file.  Generic declaration
+       of `struct ether_addr'.
+       * sysdeps/unix/sysv/linux/netinet/if_ether.h: New file.  Linux specific
+       declaration of `struct ether_addr'.
+
+       * wcsmbs/mbrtowc.c: Handle case where argument PS is NULL.
+       * wcsmbs/mbsrtowcs.c: Ditto.
+       * wcsmbs/wcrtomb.c: Ditto.
+       * wcsmbs/wcsrtombs.c: Ditto.
+
+       * wcsmbs/mbsinit.c: Prepare for PS being NULL.
+
 Wed Jun 26 13:19:35 1996  Miles Bader  <miles@gnu.ai.mit.edu>
 
        * hurd/get-host.c <fcntl.h>: New include.
index 4dca43a5c869dd713a0fc39155b043d6a074bfd4..37b73eaf599211d4f50640a53605ec343cfff3fe 100644 (file)
@@ -310,7 +310,7 @@ read_input_file (struct catalog *current, const char *fname)
          else if (strncmp (&this_line[1], "set", 3) == 0)
            {
              int cnt = sizeof ("cnt");
-             size_t set_number;
+             int set_number;
              const char *symbol = NULL;
              while (isspace (this_line[cnt]))
                ++cnt;
@@ -987,7 +987,7 @@ read_old (struct catalog *catalog, const char *file_name)
        /* No message in this slot.  */
        continue;
 
-      if (old_cat_obj.name_ptr[cnt * 3 + 0] - 1 != last_set)
+      if (old_cat_obj.name_ptr[cnt * 3 + 0] - 1 != (u_int32_t) last_set)
        {
          last_set = old_cat_obj.name_ptr[cnt * 3 + 0] - 1;
          set = find_set (catalog, old_cat_obj.name_ptr[cnt * 3 + 0] - 1);
@@ -997,14 +997,14 @@ read_old (struct catalog *catalog, const char *file_name)
       message = set->messages;
       while (message != NULL)
        {
-         if (message->number >= old_cat_obj.name_ptr[cnt * 3 + 1])
+         if ((u_int32_t) message->number >= old_cat_obj.name_ptr[cnt * 3 + 1])
            break;
          last = message;
          message = message->next;
        }
 
       if (message == NULL
-         || message->number > old_cat_obj.name_ptr[cnt * 3 + 1])
+         || (u_int32_t) message->number > old_cat_obj.name_ptr[cnt * 3 + 1])
        {
          /* We have found a message which is not yet in the catalog.
             Insert it at the right position.  */
index a70055792477ae73c95b46c0c5d51d8c722898c5..73c15c647943293ecfccad753d1feebd40064083 100644 (file)
@@ -16,7 +16,7 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
+#include <alloca.h>
 #include <unistd.h>
 #include <string.h>
 #include <grp.h>
@@ -28,8 +28,9 @@ Cambridge, MA 02139, USA.  */
    by reading the group database and using all groups
    of which USER is a member.  Also include GROUP.  */
 int
-DEFUN(initgroups, (user, group),
-      CONST char *user AND gid_t group)
+initgroups (user, group)
+     const char *user;
+     gid_t group;
 {
 #if defined (NGROUPS_MAX) && NGROUPS_MAX == 0
 
@@ -40,21 +41,23 @@ DEFUN(initgroups, (user, group),
 
   struct group *g;
   register size_t n;
+  size_t ngroups;
+  gid_t *groups;
 #ifdef NGROUPS_MAX
-  gid_t groups[NGROUPS_MAX];
+# define limit NGROUPS_MAX
+
+  ngroups = limit;
 #else
   long int limit = sysconf (_SC_NGROUPS_MAX);
-  gid_t *groups;
-  size_t ngroups;
 
   if (limit > 0)
     ngroups = limit;
   else
     /* No fixed limit on groups.  Pick a starting buffer size.  */
     ngroups = 16;
+#endif
 
   groups = __alloca (ngroups * sizeof *groups);
-#endif
 
   setgrent ();
 
index da300c7376c12abe6e39549190bd752c3f7089b7..197e9d03a4290105dfbef9ed2669b811523b4fb0 100644 (file)
@@ -21,7 +21,8 @@
 #
 subdir := inet
 
-headers        := netinet/in.h $(wildcard arpa/*.h protocols/*.h)
+headers        := netinet/ether.h netinet/in.h netinet/if_ether.h \
+          $(wildcard arpa/*.h protocols/*.h)
 
 routines := ntohl ntohs htonl htons            \
            inet_lnaof inet_mkadr       \
@@ -35,6 +36,8 @@ routines := ntohl ntohs htonl htons           \
            getservent_r        \
            getrpcent getrpcbyname getrpcbynumber \
            getrpcent_r getrpcbyname_r getrpcbynumber_r \
+           ether_aton ether_aton_r ether_hton ether_line \
+           ether_ntoa ether_ntoa_r ether_ntoh \
            rcmd rexec ruserpass
 
 # No warnings about losing BSD code.
diff --git a/inet/ether_aton.c b/inet/ether_aton.c
new file mode 100644 (file)
index 0000000..eb27b24
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+struct ether_addr *
+ether_aton (const char *asc)
+{
+  struct ether_addr result;
+
+  return ether_aton_r (asc, &result);
+}
diff --git a/inet/ether_aton_r.c b/inet/ether_aton_r.c
new file mode 100644 (file)
index 0000000..4b38f03
--- /dev/null
@@ -0,0 +1,63 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+struct ether_addr *
+ether_aton_r (const char *asc, struct ether_addr *addr)
+{
+  size_t cnt;
+
+  for (cnt = 0; cnt < 6; ++cnt)
+    {
+      unsigned int number;
+      char ch;
+
+      ch = tolower (*asc++);
+      if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+       return NULL;
+      number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+      ch = tolower (*asc);
+      if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch)))
+       {
+         ++asc;
+         if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+           return NULL;
+         number <<= 4;
+         number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+         ch = *asc;
+         if (cnt < 5 && ch != ':')
+           return NULL;
+       }
+
+      /* Store result.  */
+      addr->ether_addr_octet[cnt] = (unsigned char) number;
+
+      /* Skip ':'.  */
+      ++asc;
+    }
+
+  return addr;
+}
diff --git a/inet/ether_hton.c b/inet/ether_hton.c
new file mode 100644 (file)
index 0000000..fb62d2d
--- /dev/null
@@ -0,0 +1,82 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+#include "../nss/nsswitch.h"
+
+/* Because the `ethers' lookup does not fit so well in the scheme so
+   we define a dummy struct here which helps us to use the available
+   functions.  */
+struct etherent
+{
+  const char *e_name;
+  struct ether_addr e_addr;
+};
+
+
+/* Type of the lookup function we need here.  */
+typedef int (*lookup_function) (const char *, struct etherent *, char *, int);
+
+
+int
+ether_hostton (const char *hostname, struct ether_addr *addr)
+{
+  static service_user *startp = NULL;
+  static lookup_function start_fct;
+  service_user *nip;
+  lookup_function fct;
+  int no_more;
+  int result;
+  enum nss_status status = NSS_STATUS_UNAVAIL;
+  struct etherent etherent;
+
+  if (startp == NULL)
+    {
+      no_more = __nss_ethers_lookup (&nip, "gethostton_r", (void **) &fct);
+      if (no_more)
+       startp = (service_user *) -1;
+      else
+       {
+         startp = nip;
+         start_fct = fct;
+       }
+    }
+  else
+    {
+      fct = start_fct;
+      no_more = (nip = startp) == (service_user *) -1;
+    }
+
+  while (no_more == 0)
+    {
+      char buffer[1024];
+
+      status = (*fct) (hostname, &etherent, buffer, sizeof buffer);
+
+      no_more = __nss_next (&nip, "gethostton_r", (void **) &fct, status, 0);
+    }
+
+  if (status == NSS_STATUS_SUCCESS)
+    memcpy (addr, etherent.e_addr.ether_addr_octet,
+           sizeof (struct ether_addr));
+
+  return status == NSS_STATUS_SUCCESS ? 0 : -1;
+}
diff --git a/inet/ether_line.c b/inet/ether_line.c
new file mode 100644 (file)
index 0000000..1400f5a
--- /dev/null
@@ -0,0 +1,79 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <stdlib.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+int
+ether_line (const char *line, struct ether_addr *addr, char *hostname)
+{
+  size_t cnt;
+  char *cp;
+
+  for (cnt = 0; cnt < 6; ++cnt)
+    {
+      unsigned int number;
+      char ch;
+
+      ch = tolower (*line++);
+      if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+       return -1;
+      number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+      ch = tolower (*line);
+      if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch)))
+       {
+         ++line;
+         if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
+           return -1;
+         number <<= 4;
+         number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
+
+         ch = *line;
+         if (cnt < 5 && ch != ':')
+           return -1;
+       }
+
+      /* Store result.  */
+      addr->ether_addr_octet[cnt] = (unsigned char) number;
+
+      /* Skip ':'.  */
+      if (ch != '\0')
+       ++line;
+    }
+
+  /* Remove trailing white space.  */
+  cp = strchr (line, '#');
+  if (cp == NULL)
+    cp = strchr (line, '\0');
+  while (cp > line && isspace (cp[-1]))
+    --cp;
+  *cp = '\0';
+
+  if (*line == '\0')
+    /* No hostname.  */
+    return -1;
+
+  /* XXX This can cause trouble because the hostname might be too long
+     but we have no possibility to check it here.  */
+  strcpy (hostname, line);
+
+  return 0;
+}
diff --git a/inet/ether_ntoa.c b/inet/ether_ntoa.c
new file mode 100644 (file)
index 0000000..728f841
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+char *
+ether_ntoa (const struct ether_addr *addr)
+{
+  char asc[18];
+
+  return ether_ntoa_r (addr, asc);
+}
diff --git a/inet/ether_ntoa_r.c b/inet/ether_ntoa_r.c
new file mode 100644 (file)
index 0000000..a2735ab
--- /dev/null
@@ -0,0 +1,33 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <stdio.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+
+char *
+ether_ntoa_r (const struct ether_addr *addr, char *buf)
+{
+  sprintf (buf, "%x:%x:%x:%x:%x:%x",
+          addr->ether_addr_octet[0], addr->ether_addr_octet[1],
+          addr->ether_addr_octet[2], addr->ether_addr_octet[3],
+          addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
+  return buf;
+}
diff --git a/inet/ether_ntoh.c b/inet/ether_ntoh.c
new file mode 100644 (file)
index 0000000..26a4e47
--- /dev/null
@@ -0,0 +1,85 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+
+#include "../nss/nsswitch.h"
+
+/* Because the `ethers' lookup does not fit so well in the scheme so
+   we define a dummy struct here which helps us to use the available
+   functions.  */
+struct etherent
+{
+  const char *e_name;
+  struct ether_addr e_addr;
+};
+
+
+/* Type of the lookup function we need here.  */
+typedef int (*lookup_function) (const struct ether_addr *, struct etherent *,
+                               char *, int);
+
+
+int
+ether_ntohost (char *hostname, const struct ether_addr *addr)
+{
+  static service_user *startp = NULL;
+  static lookup_function start_fct;
+  service_user *nip;
+  lookup_function fct;
+  int no_more;
+  int result;
+  enum nss_status status = NSS_STATUS_UNAVAIL;
+  struct etherent etherent;
+
+  if (startp == NULL)
+    {
+      no_more = __nss_ethers_lookup (&nip, "getntohost_r", (void **) &fct);
+      if (no_more)
+       startp = (service_user *) -1;
+      else
+       {
+         startp = nip;
+         start_fct = fct;
+       }
+    }
+  else
+    {
+      fct = start_fct;
+      no_more = (nip = startp) == (service_user *) -1;
+    }
+
+  while (no_more == 0)
+    {
+      char buffer[1024];
+
+      status = (*fct) (addr, &etherent, buffer, sizeof buffer);
+
+      no_more = __nss_next (&nip, "getntohost_r", (void **) &fct, status, 0);
+    }
+
+  if (status == NSS_STATUS_SUCCESS)
+    /* XXX This is a potential cause of trouble because the size of
+       the HOSTNAME buffer is not known but the interface does not
+       provide this information.  */
+    strcpy (hostname, etherent.e_name);
+
+  return status == NSS_STATUS_SUCCESS ? 0 : -1;
+}
diff --git a/inet/netinet/ether.h b/inet/netinet/ether.h
new file mode 100644 (file)
index 0000000..b14377a
--- /dev/null
@@ -0,0 +1,48 @@
+/* Functions for storing Ethernet addresses in ASCII and mapping to hostnames.
+Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#ifndef __NETINET_ETHER_H
+
+#define __NETINET_ETHER_H      1
+#include <features.h>
+
+/* Get definition of `struct ether_addr'.  */
+#include <netinet/if_ether.h>
+
+
+/* Convert 48 bit Ethernet ADDRess to ASCII.  */
+char *ether_ntoa __P ((const struct ether_addr *__addr));
+char *ether_ntoa_r __P ((const struct ether_addr *__addr, char *__buf));
+
+/* Convert ASCII string S to 48 bit Ethernet address.  */
+struct ether_addr *ether_aton __P ((const char *__asc));
+struct ether_addr *ether_aton_r __P ((const char *__asc,
+                                     struct ether_addr *__addr));
+
+/* Map 48 bit Ethernet number ADDR to HOSTNAME.  */
+int ether_ntohost __P ((char *__hostname, const struct ether_addr *__addr));
+
+/* Map HOSTNAME to 48 bit Ethernet address.  */
+int ether_hostton __P ((const char *__hostname, struct ether_addr *__addr));
+
+/* Scan LINE and set ADDR and HOSTNAME.  */
+int ether_line __P ((const char *__line, struct ether_addr *__addr,
+                    char *__hostname));
+
+#endif /* netinet/ether.h */
diff --git a/netinet/ether.h b/netinet/ether.h
new file mode 100644 (file)
index 0000000..60ef5a3
--- /dev/null
@@ -0,0 +1 @@
+#include <inet/netinet/ether.h>
index 91c4ef7380a19fd99a19232e9c452025e4fce7e5..bdf1651bb1aece7e5fe18a0b52df6a420354f482 100644 (file)
@@ -25,10 +25,10 @@ distribute          := nsswitch.h XXX-lookup.c getXXbyYY.c getXXbyYY_r.c \
                           getXXent.c getXXent_r.c
 
 # This is the trivial part which goes into libc itself.
-routines               := nsswitch \
-                          $(addsuffix -lookup,proto service host network \
-                                              grp pwd rpc)
+routines               = nsswitch $(addsuffix -lookup,$(databases))
 
+# These are the databases that go through nss dispatch.
+databases              = proto service host network grp pwd rpc ethers
 
 # Specify rules for the nss_* modules.  We have some services.
 services               := files dns
@@ -36,12 +36,11 @@ services            := files dns
 extra-libs             = $(services:%=libnss_%)
 
 # The sources are found in the appropriate subdir.
-subdir-dirs = nss_files nss_dns
+subdir-dirs = $(services:%=nss_%)
 vpath %.c $(subdir-dirs)
 
 
-libnss_files-routines  := files-proto files-service files-network \
-                          files-hosts files-grp files-pwd files-rpc
+libnss_files-routines  := $(addprefix files-,$(databases))
 distribute             += files-XXX.c files-parse.c
 
 libnss_dns-routines    := dns-host dns-network
diff --git a/nss/ethers-lookup.c b/nss/ethers-lookup.c
new file mode 100644 (file)
index 0000000..7746781
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME ethers
+
+#include "XXX-lookup.c"
index 3d1e9593e6d7f70f05a6530661a548928b659dab..07e575997aaa6056c5680aa1d41d0581e0f6900e 100644 (file)
@@ -101,7 +101,7 @@ extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp);
 
 
 void
-APPEND_R (SETFUNC_NAME) (STAYOPEN)
+SETFUNC_NAME (STAYOPEN)
 {
   set_function fct;
   int no_more;
@@ -138,7 +138,7 @@ APPEND_R (SETFUNC_NAME) (STAYOPEN)
 
 
 void
-APPEND_R (ENDFUNC_NAME) (void)
+ENDFUNC_NAME (void)
 {
   end_function fct;
   int no_more;
index 40bb7df81eedcbfccd0fbe219ac83601d0c8db54..7291c75d844640d3d35b388e7a49f12d95cc5d4a 100644 (file)
@@ -102,9 +102,6 @@ internal_endent (void)
       fclose (stream);
       stream = NULL;
     }
-
-  /* Reset STAYOPEN flag.  */
-  keep_stream = 0;
 }
 
 
@@ -116,6 +113,9 @@ CONCAT(_nss_files_end,ENTNAME) (void)
 
   internal_endent ();
 
+  /* Reset STAYOPEN flag.  */
+  keep_stream = 0;
+
   __libc_lock_unlock (lock);
 
   return NSS_STATUS_SUCCESS;
@@ -131,15 +131,17 @@ internal_getent (struct STRUCTURE *result,
   struct parser_data *data = (void *) buffer;
   int linebuflen = buffer + buflen - data->linebuffer;
 
-  /* Someone called internal_setent before calling us, so if the
-     stream is not open now the file could not be opened.  */
+  /* Be prepared that the set*ent function was not called before.  */
   if (stream == NULL)
     {
-      H_ERRNO_SET (NETDB_INTERNAL);
-      return NSS_STATUS_UNAVAIL;
+      enum nss_status status;
+
+      status = internal_setent (0);
+      if (status != NSS_STATUS_SUCCESS)
+       return status;
     }
 
-  if (buflen < sizeof *data + 1)
+  if (buflen < (int) sizeof *data + 1)
     {
       errno = ERANGE;
       return NSS_STATUS_NOTFOUND;
@@ -155,6 +157,9 @@ internal_getent (struct STRUCTURE *result,
          return NSS_STATUS_NOTFOUND;
        }
 
+      /* Terminate the line for any case.  */
+      data->linebuffer[linebuflen - 1] = '\0';
+
       /* Skip leading blanks.  */
       while (isspace (*p))
        ++p;
diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c
new file mode 100644 (file)
index 0000000..e7579a4
--- /dev/null
@@ -0,0 +1,73 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <string.h>
+#include <netinet/if_ether.h>
+
+/* Because the `ethers' lookup does not fit so well in the scheme so
+   we define a dummy struct here which helps us to use the available
+   functions.  */
+struct etherent
+{
+  const char *e_name;
+  struct ether_addr e_addr;
+};
+struct etherent_data {};
+
+#define ENTNAME                etherent
+#define DATAFILE       "/etc/ethers"
+#include "files-parse.c"
+LINE_PARSER
+(
+ MIDLINE_COMMENTS;
+ /* Read the ethernet address: 6 x 8bit hexadecimal number.  */
+ {
+   size_t cnt;
+
+   for (cnt = 0; cnt < 6; ++cnt)
+     {
+       unsigned int number;
+
+       if (cnt < 5)
+        INT_FIELD (number, ISCOLON , 0, 16, (unsigned int))
+       else
+        INT_FIELD (number, isspace, 0, 16, (unsigned int))
+
+       if (number > 0xff)
+        return 0;
+       result->e_addr.ether_addr_octet[cnt] = number;
+     }
+ };
+ STRING_FIELD (result->e_name, isspace, 1);
+ )
+
+
+#include "files-XXX.c"
+
+DB_LOOKUP (hostton,
+          {
+            if (strcmp (result->e_name, name) == 0)
+              break;
+          }, const char *name)
+
+DB_LOOKUP (ntohost,
+          {
+            if (memcmp (&result->e_addr, addr,
+                        sizeof (struct ether_addr)) == 0)
+              break;
+          }, struct ether_addr *addr)
index 38c710279a47dd182a0a7d36b6e632c7316a90b5..8eda3ba41d44adff7f7a653147ea15d1f736874b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,62 +16,30 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include <ctype.h>
-#include <stddef.h>
 #include <stdlib.h>
+#include <wchar.h>
 
 
-extern int _mb_shift;  /* Defined in mbtowc.c.  */
+extern mbstate_t __no_r_state; /* Defined in mbtowc.c.  */
 
 /* Convert the string of multibyte characters in S to `wchar_t's in
    PWCS, writing no more than N.  Return the number written,
-   or (size_t) -1 if an invalid multibyte character is encountered.  */
+   or (size_t) -1 if an invalid multibyte character is encountered.
+
+   Attention: this function should NEVER be intentionally used.
+   The interface is completely stupid.  The state is shared between
+   all conversion functions.  You should use instead the restartable
+   version `mbsrtowcs'.  */
 size_t
-DEFUN(mbstowcs, (pwcs, s, n),
-      register wchar_t *pwcs AND register CONST char *s AND register size_t n)
+mbstowcs (wchar_t *pwcs, const char *s, size_t n)
 {
-  int save_shift;
-  register size_t written = 0;
-
-  /* Save the shift state.  */
-  save_shift = _mb_shift;
-  /* Reset the shift state.  */
-  _mb_shift = 0;
-
-  while (*s != '\0')
-    {
-      int len;
-      if (isascii (*s))
-       {
-         *pwcs = (wchar_t) *s;
-         len = 1;
-       }
-      else
-       len = mbtowc (pwcs, s, n);
-
-      if (len < 1)
-       {
-         /* Return an error.  */
-         written = (size_t) -1;
-         break;
-       }
-      else
-       {
-         /* Multibyte character converted.  */
-         ++pwcs;
-         ++written;
-         s += len;
-         n -= len;
-       }
-    }
+  mbstate_t save_shift = __no_r_state;
+  size_t written;
 
-  /* Terminate the string if it has space.  */
-  if (n > 0)
-    *pwcs = (wchar_t) 0;
+  written = mbsrtowcs (pwcs, s, n, &__no_r_state);
 
   /* Restore the old shift state.  */
-  _mb_shift = save_shift;
+  __no_r_state = save_shift;
 
   /* Return how many we wrote (or maybe an error).  */
   return written;
index fd9449251c6e88826f7f9cfcb3dbda5061a278c9..c340dd72a65895234f78a0d52a57aaee4ebe59d7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,73 +16,41 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include "../locale/localeinfo.h"
-#include <ctype.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <wchar.h>
 
 
-long int _mb_shift = 0;
+/* Common state for all non-restartable conversion functions.  */
+mbstate_t __no_r_state;
 
 /* Convert the multibyte character at S, which is no longer
    than N characters, to its `wchar_t' representation, placing
-   this n *PWC and returning its length.  */
+   this n *PWC and returning its length.
+
+   Attention: this function should NEVER be intentionally used.
+   The interface is completely stupid.  The state is shared between
+   all conversion functions.  You should use instead the restartable
+   version `mbrtowc'.  */
 int
-DEFUN(mbtowc, (pwc, s, n), wchar_t *pwc AND CONST char *s AND size_t n)
+mbtowc (wchar_t *pwc, const char *s, size_t n)
 {
-#if 0
-  register CONST mb_char *mb;
-  register wchar_t i;
-#endif
-
+  int result;
+
+  /* If S is NULL the function has to return null or not null
+     depending on the encoding having a state depending encoding or
+     not.  This is nonsense because any multibyte encoding has a
+     state.  The ISO C amendment 1 corrects this while introducing the
+     restartable functions.  We simply say here all encodings have a
+     state.  */
   if (s == NULL)
-    return _mb_shift != 0;
-
-  if (*s == '\0')
-    /* ANSI 4.10.7.2, line 19.  */
-    return 0;
-
-  if (isascii (*s))
-    {
-      /* A normal ASCII character translates to itself.  */
-      if (pwc != NULL)
-       *pwc = (wchar_t) *s;
-      return 1;
-    }
-
-#if 0
-  if (_ctype_info->mbchar == NULL ||
-      _ctype_info->mbchar->mb_chars == NULL)
-    return -1;
+    return 1;
 
-  if (n > MB_CUR_MAX)
-    n = MB_CUR_MAX;
+  result = mbrtowc (pwc, s, n, &__no_r_state);
 
-  for (i = 0; i < WCHAR_MAX; ++i)
-    {
-      mb = &_ctype_info->mbchar->mb_chars[i];
-      /* EOF and NUL aren't MB chars.  */
-      if (i == (wchar_t) EOF || i == (wchar_t) '\0')
-       continue;
-      /* Normal ASCII values can't start MB chars.  */
-      else if (isascii(i))
-       continue;
-      else if (mb->string == NULL || mb->len == 0)
-       continue;
-      else if (mb->len > n)
-       continue;
-      else if (!strncmp(mb->string, s, mb->len))
-       {
-         _mb_shift += mb->shift;
-         if (pwc != NULL)
-           *pwc = i;
-         return mb->len;
-       }
-    }
-#endif
+  /* The `mbrtowc' functions tell us more than we need.  Fold the -1
+     and -2 result into -1.  */
+  if (result < 0)
+    result = -1;
 
-  return -1;
+  return result;
 }
index 6ddbfb17252a5b6a5d0f54ecaf2ad15f15589a1f..65183081817396bd39cf3b812dafb896834d0fab 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,69 +16,31 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include "../locale/localeinfo.h"
-#include <ctype.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <wchar.h>
 
 
+extern mbstate_t __no_r_state; /* Defined in mbtowc.c.  */
+
 /* Convert the `wchar_t' string in PWCS to a multibyte character string
    in S, writing no more than N characters.  Return the number of bytes
-   written, or (size_t) -1 if an invalid `wchar_t' was found.  */
+   written, or (size_t) -1 if an invalid `wchar_t' was found.
+
+   Attention: this function should NEVER be intentionally used.
+   The interface is completely stupid.  The state is shared between
+   all conversion functions.  You should use instead the restartable
+   version `wcsrtombs'.  */
 size_t
-DEFUN(wcstombs, (s, pwcs, n),
-      register char *s AND register CONST wchar_t *pwcs AND register size_t n)
+wcstombs (char *s, const wchar_t *pwcs, size_t n)
 {
-#if 0
-  register CONST mb_char *mb;
-  register int shift = 0;
-#endif
-
-  register size_t written = 0;
-  register wchar_t w;
+  mbstate_t save_shift = __no_r_state;
+  size_t written;
 
-  while ((w = *pwcs++) != (wchar_t) '\0')
-    {
-      if (isascii (w))
-       {
-         /* A normal character.  */
-         *s++ = (unsigned char) w;
-         --n;
-         ++written;
-       }
-      else
-       {
-#if 1
-         written = (size_t) -1;
-         break;
-#else
-         mb = &_ctype_info->mbchar->mb_chars[w + shift];
-         if (mb->string == NULL || mb->len == 0)
-           {
-             written = (size_t) -1;
-             break;
-           }
-         else if (mb->len > n)
-           break;
-         else
-           {
-             memcpy ((PTR) s, (CONST PTR) mb->string, mb->len);
-             s += mb->len;
-             n -= mb->len;
-             written += mb->len;
-             shift += mb->shift;
-           }
-#endif
-       }
-    }
+  written = mbsrtowcs (pwcs, s, n, &__no_r_state);
 
-  /* Terminate the string if it has space.  */
-  if (n > 0)
-    *s = '\0';
+  /* Restore the old shift state.  */
+  __no_r_state = save_shift;
 
-  /* Return the number of characters written (or maybe an error).  */
+  /* Return how many we wrote (or maybe an error).  */
   return written;
 }
index 15f32ab71f2054f21f5533131768f904851a8e7d..f7143add82f22dd88de9a76cbcef06f1474598bc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,63 +16,30 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include "../locale/localeinfo.h"
-#include <stddef.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
+#include <wchar.h>
 
 
-extern long int _mb_shift;     /* Defined in mbtowc.c.  */
+extern mbstate_t __no_r_state; /* Defined in mbtowc.c.  */
 
 /* Convert WCHAR into its multibyte character representation,
-   putting this in S and returning its length.  */
+   putting this in S and returning its length.
+
+   Attention: this function should NEVER be intentionally used.
+   The interface is completely stupid.  The state is shared between
+   all conversion functions.  You should use instead the restartable
+   version `wcrtomb'.  */
 int
-DEFUN(wctomb, (s, wchar), register char *s AND wchar_t wchar)
+wctomb (char *s, wchar_t wchar)
 {
-#if 0
-  register CONST mb_char *mb;
-
-  if (_ctype_info->mbchar == NULL)
-    mb = NULL;
-  else
-    mb = _ctype_info->mbchar->mb_chars;
-#endif
-
-  /* If S is NULL, just say if we're shifted or not.  */
+  /* If S is NULL the function has to return null or not null
+     depending on the encoding having a state depending encoding or
+     not.  This is nonsense because any multibyte encoding has a
+     state.  The ISO C amendment 1 corrects this while introducing the
+     restartable functions.  We simply say here all encodings have a
+     state.  */
   if (s == NULL)
-    return _mb_shift != 0;
-
-  if (wchar == (wchar_t) '\0')
-    {
-      _mb_shift = 0;
-      /* See ANSI 4.4.1.1, line 21.  */
-      if (s != NULL)
-       *s = '\0';
-      return 1;
-    }
-  else /* if (mb == NULL) */
-    {
-      if ((wchar_t) (char) wchar == wchar && isascii ((char) wchar))
-       {
-         /* A normal ASCII character translates to itself.  */
-         if (s != NULL)
-           *s = (char) wchar;
-         return 1;
-       }
-      return -1;
-    }
+    return 1;
 
-#if 1
-  return -1;
-#else
-  mb += wchar + _mb_shift;
-  if (mb->string == NULL || mb->len == 0)
-    return -1;
-  memcpy((PTR) s, (CONST PTR) mb->string, mb->len + 1);
-  _mb_shift += mb->shift;
-  return mb->len;
-#endif
+  return wcrtomb (s, wchar, &__no_r_state);
 }
index 99106c458330ceb8c478ea4649382471f33483a0..f67e7247d4b83dbf2950e57bdebb5ddd860d0227 100644 (file)
@@ -24,7 +24,8 @@ subdir        := string
 headers        := string.h strings.h memory.h endian.h bytesex.h \
           argz.h envz.h
 
-routines       := strcat strchr strcmp strcoll strcpy strcspn strdup   \
+routines       := strcat strchr strcmp strcoll strcpy strcspn          \
+                  strdup strndup       \
                   strerror _strerror strerror_r strlen strnlen         \
                   strncat strncmp strncpy                              \
                   strrchr strpbrk strsignal strspn strstr strtok       \
index 2c8aff27967d24a31551609cec667a715905bd9b..3e9eee0945820fc876e701fdf93c9168f89676cd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,7 +16,6 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
@@ -24,15 +23,16 @@ Cambridge, MA 02139, USA.  */
 
 /* Duplicate S, returning an identical malloc'd string.  */
 char *
-DEFUN(strdup, (s), CONST char *s)
+__strdup (const char *s)
 {
-  size_t len = strlen(s) + 1;
-  PTR new = malloc(len);
+  size_t len = strlen (s) + 1;
+  void *new = malloc (len);
 
   if (new == NULL)
     return NULL;
 
-  memcpy(new, (PTR) s, len);
+  memcpy (new, s, len);
 
   return (char *) new;
 }
+weak_alias (__strdup, strdup)
index a5a6edd398880cd2938ea409049c830dfcf7a3fc..3b6c5e969b721ebe9f86fb317ef1c1c7864a8438 100644 (file)
@@ -49,9 +49,6 @@ extern __ptr_t __memccpy __P ((__ptr_t __dest, __const __ptr_t __src,
 #if defined (__USE_SVID) || defined (__USE_BSD)
 extern __ptr_t memccpy __P ((__ptr_t __dest, __const __ptr_t __src,
                             int __c, size_t __n));
-#ifdef __OPTIMIZE__
-#define        memccpy(dest, src, c, n) __memccpy((dest), (src), (c), (n))
-#endif /* Optimizing.  */
 #endif /* SVID.  */
 
 
@@ -88,6 +85,7 @@ extern size_t strxfrm __P ((char *__dest, __const char *__src, size_t __n));
 
 #if defined (__USE_SVID) || defined (__USE_BSD)
 /* Duplicate S, returning an identical malloc'd string.  */
+extern char *__strdup __P ((__const char *__s));
 extern char *strdup __P ((__const char *__s));
 #endif
 
@@ -95,9 +93,22 @@ extern char *strdup __P ((__const char *__s));
 /* Duplicate S, returning an identical alloca'd string.  */
 #define strdupa(s)                                                           \
 ({                                                                           \
-    const char *__old = (s);                                                 \
-    size_t __len = strlen (__old) + 1;                                       \
-    memcpy (__builtin_alloca (__len), __old, __len);                         \
+  __const char *__old = (s);                                                 \
+  size_t __len = strlen (__old) + 1;                                         \
+  memcpy (__builtin_alloca (__len), __old, __len);                           \
+})
+
+/* Return a malloc'd copy of at most N bytes of STRING.  The
+   resultant string is terminated even if no null terminator
+   appears before STRING[N].  */
+extern char *strndup __P ((__const char *__string, size_t __n));
+
+/* Return an alloca'd copy of at most N bytes of string.  */
+#define strndupa(s, n)                                                       \
+({                                                                           \
+  __const char *__old = (s);                                                 \
+  size_t __len = strnlen (__old) + 1;                                        \
+  memcpy (__builtin_alloca (__len), __old, __len);                           \
 })
 #endif
 
diff --git a/string/strndup.c b/string/strndup.c
new file mode 100644 (file)
index 0000000..213a0c0
--- /dev/null
@@ -0,0 +1,37 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+char *
+strndup (const char *s, size_t n)
+{
+  size_t len = strnlen (s) + 1;
+  char *new = malloc (len);
+
+  if (new == NULL)
+    return NULL;
+
+  memcpy (new, s, len);
+
+  return new;
+}
+
index d20af94b656dfd3d95f8612d50a888e9ae78bee2..a5241a512065c0631503c7a544204bd204c2f46d 100644 (file)
@@ -162,10 +162,13 @@ xdr_u_int(xdrs, up)
        } else if (sizeof (u_int) == sizeof (u_short)) {
                return (xdr_short(xdrs, (short *)up));
        } else {
+         abort ();             /* drepper@gnu */
+#if 0
                /* force unresolved reference (link-time error): */
                extern unexpected_sizes_in_xdr_u_int ();
 
                unexpected_sizes_in_xdr_u_int();
+#endif
        }
 #endif
 }
index c751936776b76b7c90eea743f1c01905dfa3dcd1..bc80b5985d9d70e4d30777844a25b77dbf60ef45 100644 (file)
@@ -179,8 +179,8 @@ elf_machine_rela (struct link_map *map,
 
       if (resolve)
        {
-          loadbase = (*resolve)(&sym, (Elf64_Addr)reloc_addr,
-                               r_info == R_ALPHA_JMP_SLOT);
+         loadbase = (*resolve)(&sym, (Elf64_Addr)reloc_addr, 
+                               r_info == R_ALPHA_JMP_SLOT);
        }
       else
        loadbase = map->l_addr;
diff --git a/sysdeps/generic/netinet/if_ether.h b/sysdeps/generic/netinet/if_ether.h
new file mode 100644 (file)
index 0000000..d377bbd
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#ifndef __NETINET_IF_ETHER_H
+
+#define __NETINET_IF_ETHER_H   1
+#include <features.h>
+
+/* This is a name for the 48 bit ethernet address available on many
+   systems.  */
+struct ether_addr
+{
+  unsigned char ether_addr_octet[6];
+};
+
+#endif /* netinet/if_ether.h */
diff --git a/sysdeps/unix/sysv/linux/netinet/if_ether.h b/sysdeps/unix/sysv/linux/netinet/if_ether.h
new file mode 100644 (file)
index 0000000..0da5a5a
--- /dev/null
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#ifndef __NETINET_IF_ETHER_H
+
+#define __NETINET_IF_ETHER_H   1
+#include <features.h>
+
+/* Get definitions from kernel header file.  */
+#include <linux/if_ether.h>
+
+
+/* This is a name for the 48 bit ethernet address available on many
+   systems.  */
+struct ether_addr
+{
+  unsigned char ether_addr_octet[ETH_ALEN];
+};
+
+#endif /* netinet/if_ether.h */
index 317dec23fe7cbafe85a475188355539cb326d813..d29577ff6cb1158e92e1f5842dee5d1395df9c16 100644 (file)
@@ -2,8 +2,8 @@
 
 adjtimex       adjtime adjtimex        1       __adjtimex
 bdflush                -       bdflush         2       bdflush
-create_module  -       create_module   3       create_module
-delete_module  -       delete_module   3       delete_module
+create_module  EXTRA   create_module   3       create_module
+delete_module  EXTRA   delete_module   3       delete_module
 fdatasync      -       fdatasync       1       fdatasync
 flock          -       flock           2       __flock         flock
 fork           -       fork            0       __fork          fork
@@ -14,7 +14,7 @@ getpgid               -       getpgid         1       __getpgid       getpgid
 getpgrp                -       getpgrp         0       getpgrp
 getppid                -       getppid         0       __getppid       getppid
 getsid         -       getsid          1       getsid
-init_module    -       init_module     5       init_module
+init_module    EXTRA   init_module     5       init_module
 ioperm         -       ioperm          3       ioperm
 iopl           -       iopl            1       iopl
 ipc            msgget  ipc             5       __ipc
@@ -49,7 +49,7 @@ sigprocmask   -       sigprocmask     3       __sigprocmask   sigprocmask
 s_sysctl       sysctl  _sysctl         1       __syscall__sysctl
 sysinfo                -       sysinfo         1       sysinfo
 swapon         -       swapon          2       swapon
-klogctl                -       syslog          3       klogctl
+klogctl                EXTRA   syslog          3       klogctl
 umount         -       umount          1       __umount        umount
 uselib         -       uselib          1       uselib
 wait4          -       wait4           4       __wait4         wait4
index 17083196bd6a347ba854aafeb38f8e9c13022caf..2c4b0779dae837cc73f3f8b7ff98767394dafbdc 100644 (file)
@@ -20,6 +20,8 @@ Boston, MA 02111-1307, USA.  */
 #include <wchar.h>
 
 
+static mbstate_t internal;
+
 size_t
 mbrtowc (pwc, s, n, ps)
      wchar_t *pwc;
@@ -29,6 +31,9 @@ mbrtowc (pwc, s, n, ps)
 {
   wchar_t to_wide;
 
+  if (ps == NULL)
+    ps = &internal;
+
   /*************************************************************\
   |* This is no complete implementation.  While the multi-byte *|
   |* character handling is not finished this will do.         *|
index d9f01256d51c5f7b1dbe742b6e93d97391c4b746..efbfd09347ff49c69f779f2c73f868fc5cc4aaa5 100644 (file)
@@ -17,6 +17,7 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#include <string.h>
 #include <wchar.h>
 
 
@@ -29,5 +30,5 @@ mbsinit (ps)
   |* character handling is not finished this will do.         *|
   \*************************************************************/
 
-  return *ps == 0;
+  return ps == NULL || *ps == 0;
 }
index cb87938e5d6fd8e8870cd5a8fe7cb318cdf9cc04..dc026b7252e9801c733def98a9d299b649066500 100644 (file)
@@ -20,6 +20,8 @@ Boston, MA 02111-1307, USA.  */
 #include <wchar.h>
 
 
+static mbstate_t internal;
+
 size_t
 mbsrtowcs (dst, src, len, ps)
      wchar_t *dst;
@@ -28,6 +30,10 @@ mbsrtowcs (dst, src, len, ps)
      mbstate_t *ps;
 {
   size_t result = 0;
+
+  if (ps == NULL)
+    ps = &internal;
+
   /*************************************************************\
   |* This is no complete implementation.  While the multi-byte *|
   |* character handling is not finished this will do.         *|
index 43a21625001d06916dd66f3c6545a56ada0b536b..2703e88a36010f47e3575ef281b5289f728bf4bc 100644 (file)
@@ -24,19 +24,25 @@ Boston, MA 02111-1307, USA.  */
 #define EILSEQ EINVAL
 #endif
 
+
+static mbstate_t internal;
+
 size_t
 wcrtomb (s, wc, ps)
      char *s;
      wchar_t wc;
      mbstate_t *ps;
 {
+  char fake[1];
+
+  if (ps == NULL)
+    ps = internal;
+
   /*************************************************************\
   |* This is no complete implementation.  While the multi-byte *|
   |* character handling is not finished this will do.         *|
   \*************************************************************/
 
-  char fake[1];
-
   if (s == NULL)
     {
       s = fake;
index 487237fcadad9bdcd91576eb673405648550e715..9f1000937b2541c589eacb804ce1aa774ded205a 100644 (file)
@@ -25,6 +25,8 @@ Boston, MA 02111-1307, USA.  */
 #endif
 
 
+static mbstate_t internal;
+
 size_t
 wcsrtombs (dst, src, len, ps)
      char *dst;
@@ -34,6 +36,9 @@ wcsrtombs (dst, src, len, ps)
 {
   size_t result = 0;
 
+  if (ps == NULL)
+    ps = &internal;
+
   /*************************************************************\
   |* This is no complete implementation.  While the multi-byte *|
   |* character handling is not finished this will do.         *|