From 6dbe2837567f528faa015fd0cf1536201dde5ffd Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 28 Jun 1996 08:56:59 +0000 Subject: [PATCH] Fri Jun 28 02:41:08 1996 Roland McGrath * 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 * 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 * 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. --- ChangeLog | 82 ++++++++++++++++++++++++++++ catgets/gencat.c | 8 +-- grp/initgroups.c | 17 +++--- inet/Makefile | 5 +- inet/ether_aton.c | 30 +++++++++++ inet/ether_aton_r.c | 63 ++++++++++++++++++++++ inet/ether_hton.c | 82 ++++++++++++++++++++++++++++ inet/ether_line.c | 79 +++++++++++++++++++++++++++ inet/ether_ntoa.c | 30 +++++++++++ inet/ether_ntoa_r.c | 33 ++++++++++++ inet/ether_ntoh.c | 85 ++++++++++++++++++++++++++++++ inet/netinet/ether.h | 48 +++++++++++++++++ netinet/ether.h | 1 + nss/Makefile | 11 ++-- nss/ethers-lookup.c | 22 ++++++++ nss/getXXent_r.c | 4 +- nss/nss_files/files-XXX.c | 21 +++++--- nss/nss_files/files-ethers.c | 73 +++++++++++++++++++++++++ stdlib/mbstowcs.c | 60 +++++---------------- stdlib/mbtowc.c | 84 +++++++++-------------------- stdlib/wcstombs.c | 72 ++++++------------------- stdlib/wctomb.c | 69 +++++++----------------- string/Makefile | 3 +- string/strdup.c | 12 ++--- string/string.h | 23 +++++--- string/strndup.c | 37 +++++++++++++ sunrpc/xdr.c | 3 ++ sysdeps/alpha/dl-machine.h | 4 +- sysdeps/generic/netinet/if_ether.h | 31 +++++++++++ sysdeps/unix/sysv/linux/netinet/if_ether.h | 35 ++++++++++++ sysdeps/unix/sysv/linux/syscalls.list | 8 +-- wcsmbs/mbrtowc.c | 5 ++ wcsmbs/mbsinit.c | 3 +- wcsmbs/mbsrtowcs.c | 6 +++ wcsmbs/wcrtomb.c | 10 +++- wcsmbs/wcsrtombs.c | 5 ++ 36 files changed, 904 insertions(+), 260 deletions(-) create mode 100644 inet/ether_aton.c create mode 100644 inet/ether_aton_r.c create mode 100644 inet/ether_hton.c create mode 100644 inet/ether_line.c create mode 100644 inet/ether_ntoa.c create mode 100644 inet/ether_ntoa_r.c create mode 100644 inet/ether_ntoh.c create mode 100644 inet/netinet/ether.h create mode 100644 netinet/ether.h create mode 100644 nss/ethers-lookup.c create mode 100644 nss/nss_files/files-ethers.c create mode 100644 string/strndup.c create mode 100644 sysdeps/generic/netinet/if_ether.h create mode 100644 sysdeps/unix/sysv/linux/netinet/if_ether.h diff --git a/ChangeLog b/ChangeLog index 8766083..d3ad0e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,85 @@ +Fri Jun 28 02:41:08 1996 Roland McGrath + + * 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 + + * 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 + + * 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 * hurd/get-host.c : New include. diff --git a/catgets/gencat.c b/catgets/gencat.c index 4dca43a..37b73ea 100644 --- a/catgets/gencat.c +++ b/catgets/gencat.c @@ -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. */ diff --git a/grp/initgroups.c b/grp/initgroups.c index a700557..73c15c6 100644 --- a/grp/initgroups.c +++ b/grp/initgroups.c @@ -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 +#include #include #include #include @@ -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 (); diff --git a/inet/Makefile b/inet/Makefile index da300c7..197e9d0 100644 --- a/inet/Makefile +++ b/inet/Makefile @@ -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 index 0000000..eb27b24 --- /dev/null +++ b/inet/ether_aton.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include + + +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 index 0000000..4b38f034 --- /dev/null +++ b/inet/ether_aton_r.c @@ -0,0 +1,63 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include +#include +#include + + +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 index 0000000..fb62d2d --- /dev/null +++ b/inet/ether_hton.c @@ -0,0 +1,82 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include + +#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, ðerent, 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 index 0000000..1400f5a --- /dev/null +++ b/inet/ether_line.c @@ -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 +#include +#include + + +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 index 0000000..728f841 --- /dev/null +++ b/inet/ether_ntoa.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include + + +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 index 0000000..a2735ab --- /dev/null +++ b/inet/ether_ntoa_r.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include +#include + + +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 index 0000000..26a4e47 --- /dev/null +++ b/inet/ether_ntoh.c @@ -0,0 +1,85 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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 +#include + +#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, ðerent, 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 index 0000000..b14377a --- /dev/null +++ b/inet/netinet/ether.h @@ -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 + +/* Get definition of `struct ether_addr'. */ +#include + + +/* 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 index 0000000..60ef5a3 --- /dev/null +++ b/netinet/ether.h @@ -0,0 +1 @@ +#include diff --git a/nss/Makefile b/nss/Makefile index 91c4ef7..bdf1651 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -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 index 0000000..7746781 --- /dev/null +++ b/nss/ethers-lookup.c @@ -0,0 +1,22 @@ +/* Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Ulrich Drepper , 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" diff --git a/nss/getXXent_r.c b/nss/getXXent_r.c index 3d1e959..07e5759 100644 --- a/nss/getXXent_r.c +++ b/nss/getXXent_r.c @@ -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; diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index 40bb7df..7291c75 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -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 index 0000000..e7579a4 --- /dev/null +++ b/nss/nss_files/files-ethers.c @@ -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 +#include + +/* 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) diff --git a/stdlib/mbstowcs.c b/stdlib/mbstowcs.c index 38c7102..8eda3ba 100644 --- a/stdlib/mbstowcs.c +++ b/stdlib/mbstowcs.c @@ -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 -#include -#include #include +#include -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; diff --git a/stdlib/mbtowc.c b/stdlib/mbtowc.c index fd94492..c340dd7 100644 --- a/stdlib/mbtowc.c +++ b/stdlib/mbtowc.c @@ -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 -#include "../locale/localeinfo.h" -#include -#include -#include #include -#include +#include -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; } diff --git a/stdlib/wcstombs.c b/stdlib/wcstombs.c index 6ddbfb1..6518308 100644 --- a/stdlib/wcstombs.c +++ b/stdlib/wcstombs.c @@ -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 -#include "../locale/localeinfo.h" -#include -#include -#include #include -#include +#include +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; } diff --git a/stdlib/wctomb.c b/stdlib/wctomb.c index 15f32ab..f7143ad 100644 --- a/stdlib/wctomb.c +++ b/stdlib/wctomb.c @@ -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 -#include "../locale/localeinfo.h" -#include -#include #include -#include -#include +#include -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); } diff --git a/string/Makefile b/string/Makefile index 99106c4..f67e724 100644 --- a/string/Makefile +++ b/string/Makefile @@ -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 \ diff --git a/string/strdup.c b/string/strdup.c index 2c8aff2..3e9eee0 100644 --- a/string/strdup.c +++ b/string/strdup.c @@ -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 #include #include #include @@ -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) diff --git a/string/string.h b/string/string.h index a5a6edd..3b6c5e9 100644 --- a/string/string.h +++ b/string/string.h @@ -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 index 0000000..213a0c0 --- /dev/null +++ b/string/strndup.c @@ -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 +#include +#include + + +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; +} + diff --git a/sunrpc/xdr.c b/sunrpc/xdr.c index d20af94..a5241a5 100644 --- a/sunrpc/xdr.c +++ b/sunrpc/xdr.c @@ -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 } diff --git a/sysdeps/alpha/dl-machine.h b/sysdeps/alpha/dl-machine.h index c751936..bc80b59 100644 --- a/sysdeps/alpha/dl-machine.h +++ b/sysdeps/alpha/dl-machine.h @@ -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 index 0000000..d377bbd --- /dev/null +++ b/sysdeps/generic/netinet/if_ether.h @@ -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 + +/* 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 index 0000000..0da5a5a --- /dev/null +++ b/sysdeps/unix/sysv/linux/netinet/if_ether.h @@ -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 + +/* Get definitions from kernel header file. */ +#include + + +/* 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 */ diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index 317dec2..d29577f 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -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 diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c index 1708319..2c4b077 100644 --- a/wcsmbs/mbrtowc.c +++ b/wcsmbs/mbrtowc.c @@ -20,6 +20,8 @@ Boston, MA 02111-1307, USA. */ #include +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. *| diff --git a/wcsmbs/mbsinit.c b/wcsmbs/mbsinit.c index d9f0125..efbfd09 100644 --- a/wcsmbs/mbsinit.c +++ b/wcsmbs/mbsinit.c @@ -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 #include @@ -29,5 +30,5 @@ mbsinit (ps) |* character handling is not finished this will do. *| \*************************************************************/ - return *ps == 0; + return ps == NULL || *ps == 0; } diff --git a/wcsmbs/mbsrtowcs.c b/wcsmbs/mbsrtowcs.c index cb87938..dc026b7 100644 --- a/wcsmbs/mbsrtowcs.c +++ b/wcsmbs/mbsrtowcs.c @@ -20,6 +20,8 @@ Boston, MA 02111-1307, USA. */ #include +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. *| diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c index 43a2162..2703e88 100644 --- a/wcsmbs/wcrtomb.c +++ b/wcsmbs/wcrtomb.c @@ -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; diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c index 487237f..9f10009 100644 --- a/wcsmbs/wcsrtombs.c +++ b/wcsmbs/wcsrtombs.c @@ -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. *| -- 2.7.4