about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog179
-rw-r--r--Rules10
-rw-r--r--assert/assert.h8
-rw-r--r--config.make.in1
-rw-r--r--db2/db/db_conv.c1
-rw-r--r--elf/dl-open.c9
-rw-r--r--elf/genrtldtbl.awk2
-rw-r--r--elf/rtld.c8
-rw-r--r--gmon/bb_exit_func.c4
-rw-r--r--grp/fgetgrent_r.c10
-rw-r--r--iconv/iconv_open.c3
-rw-r--r--inet/getnetgrent_r.c3
-rw-r--r--libc.map15
-rw-r--r--libio/freopen.c4
-rw-r--r--locale/programs/ld-collate.c2
-rw-r--r--localedata/locales/pl_PL2
-rw-r--r--localedata/locales/ru_RU2
-rw-r--r--login/Makefile16
-rw-r--r--login/forkpty.c56
-rw-r--r--login/openpty.c73
-rw-r--r--login/programs/pt_chown.c88
-rw-r--r--login/pty-internal.h41
-rw-r--r--login/utmp_file.c10
-rw-r--r--manual/Makefile4
-rw-r--r--misc/init-misc.c3
-rw-r--r--nis/nis_cache.c2
-rw-r--r--nis/nss_compat/compat-grp.c45
-rw-r--r--nis/nss_compat/compat-pwd.c48
-rw-r--r--nis/nss_compat/compat-spwd.c33
-rw-r--r--nss/Makefile4
-rw-r--r--nss/test-netdb.c349
-rw-r--r--posix/cpio.h (renamed from include/cpio.h)0
-rw-r--r--pwd/fgetpwent_r.c10
-rw-r--r--signal/signal.h4
-rw-r--r--stdio-common/printf-parse.h10
-rw-r--r--stdio-common/printf.h3
-rw-r--r--stdio-common/test-popen.c11
-rw-r--r--stdio-common/tiformat.c5
-rw-r--r--stdio-common/vfprintf.c66
-rw-r--r--stdlib/stdlib.h26
-rw-r--r--sysdeps/generic/getpt.c34
-rw-r--r--sysdeps/generic/grantpt.c35
-rw-r--r--sysdeps/generic/inttypes.h2
-rw-r--r--sysdeps/generic/ptsname.c46
-rw-r--r--sysdeps/generic/pty.c140
-rw-r--r--sysdeps/generic/unlockpt.c35
-rw-r--r--sysdeps/unix/bsd/getpt.c60
-rw-r--r--sysdeps/unix/bsd/unlockpt.c41
-rw-r--r--sysdeps/unix/grantpt.c111
-rw-r--r--sysdeps/unix/sysv/linux/Dist1
-rw-r--r--sysdeps/unix/sysv/linux/Makefile3
-rw-r--r--sysdeps/unix/sysv/linux/alpha/Dist1
-rw-r--r--sysdeps/unix/sysv/linux/arm/Dist1
-rw-r--r--sysdeps/unix/sysv/linux/bits/ioctls.h87
-rw-r--r--sysdeps/unix/sysv/linux/bits/types.h2
-rw-r--r--sysdeps/unix/sysv/linux/getpt.c76
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c3
-rw-r--r--sysdeps/unix/sysv/linux/mips/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/netrose/rose.h (renamed from sysdeps/unix/sysv/linux/m68k/sigreturn.S)16
-rw-r--r--sysdeps/unix/sysv/linux/ptsname.c108
-rw-r--r--sysdeps/unix/sysv/linux/pty.c3
-rw-r--r--sysdeps/unix/sysv/linux/siglist.c18
-rw-r--r--sysdeps/unix/sysv/linux/unlockpt.c50
63 files changed, 1788 insertions, 257 deletions
diff --git a/ChangeLog b/ChangeLog
index 79e01b099c..ffe27bf4e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,182 @@
+1998-01-30 19:58  Ulrich Drepper  <drepper@cygnus.com>
+
+	* include/cpio.h: Move to ...
+	* posix/cpio.h: ...here.
+
+	* locale/programs/ld-collate.c: Fix typo.
+
+	* signal/signal.h: Declare _sys_siglist with NSIG+1 elements.
+
+	* stdio-common/tiformat.c: Add checks for %#.0o and friends.
+
+	* login/utmp_file.c (pututline_file): Don't always report success
+	if similar entry is found.  Patch by Mark M. Kettenis.
+
+1998-01-30 16:06  Philip Blundell  <pb@nexus.co.uk>
+
+	* manual/Makefile: Don't try to install the info files if makeinfo
+	is not available.
+
+1998-01-30 12:05  Philip Blundell  <pb@nexus.co.uk>
+
+	* sysdeps/unix/sysv/linux/bits/ioctls.h: Include a copy of the
+	kernel's network ioctls, rather than using <linux/sockios.h> to
+	get them.  This way we are sure of maintaining compatibility if
+	the kernel interface should change.
+
+1998-01-30 15:52  Ulrich Drepper  <drepper@cygnus.com>
+
+	* sysdeps/unix/sysv/linux/Dist: Add netrose/rose.h.
+
+1998-01-25 19:54  Philip Blundell  <Philip.Blundell@pobox.com>
+
+	* sysdeps/unix/sysv/linux/netrose/rose.h: New file.
+	* sysdeps/unix/sysv/linux/Makefile (sysdep_headers): Install it.
+
+1998-01-27 22:29  Zack Weinberg  <zack@rabi.phys.columbia.edu>
+
+	Implement System V pseudoterminal handling.
+
+	* login/Makefile
+	(routines): Add getpt, grantpt, unlockpt, ptsname.
+	(libutil-routines): Remove pty. Add openpty, forkpty.
+	(distribute): New internal header pty-internal.h.
+	(others): Add the helper program, pt_chown.
+	(install-others): Install it, in $(libexecdir), mode 4755.
+
+	* login/pty-internal.h: New file.
+	* login/openpty.c: New file.
+	* login/forkpty.c: New file.
+	* login/programs/pt_chown.c: New file.
+
+	* libc.map: Add getpt, grantpt, unlockpt, ptsname, ptsname_r.
+	* stdlib/stdlib.h: Prototype them.
+
+	* config.make.in: Define $(libexecdir).
+	* Makeconfig: Define $(inst_libexecdir).
+
+	* sysdeps/generic/pty.c: Removed.
+	* sysdeps/unix/sysv/linux/pty.c: Removed.
+
+	* sysdeps/generic/getpt.c: Stub out.
+	* sysdeps/generic/grantpt.c: Likewise.
+	* sysdeps/generic/ptsname.c: Likewise.
+	* sysdeps/generic/unlockpt.c: Likewise.
+
+	* sysdeps/unix/grantpt.c: New file.
+	* sysdeps/unix/bsd/getpt.c: New file.
+	* sysdeps/unix/bsd/unlockpt.c: New file.
+	* sysdeps/unix/sysv/linux/getpt.c: New file.
+	* sysdeps/unix/sysv/linux/ptsname.c: New file.
+	* sysdeps/unix/sysv/linux/unlockpt.c: New file.
+
+1998-01-29 23:56  Ulrich Drepper  <drepper@cygnus.com>
+
+	* localedata/locales/ru_RU: Fix YESEXPR.  Patch by lav@yars.free.net.
+
+1998-01-29  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* nss/Makefile (tests): Add rule for test-netdb.c.
+
+	* nss/test-netdb.c: New file.
+
+1998-01-29 02:38  Ulrich Drepper  <drepper@cygnus.com>
+
+	* elf/dl-open.c (_dl_open): Make sure the variable `reloc' is
+	really kept as a variable.  Patch by Richard Henderson,
+	reported by Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz>.
+
+	* elf/rtld.c (dl_main): Call _dl_init_paths before handling preloading.
+	* elf/genrtldtbl.awk: Mark machine dependent directory of generated
+	entries as not existing.
+
+1998-01-26  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
+
+	* stdio-common/vfprintf.c (process_arg): Fix printing of octal
+	zero in alternate form with precision of zero, which must produce
+	"0".  Add braces to avoid ambiguous `else'.
+
+1998-01-26  Thorsten Kukuk  <kukuk@vt.uni-paderborn.de>
+
+	* nis/nss_compat/compat-grp.c: Fix memory leak and trailing null
+	problem with strncpy.
+	* nis/nss_compat/compat-pwd.c: Likewise.
+	* nis/nss_compat/comapt-spwd.c: Likewise.
+
+1998-01-28  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* assert/assert.h (assert_perror): Correct test for errnum.  Patch
+	by uch@nop.or.jp. [PR libc/437]
+
+1997-12-20  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
+
+	* locales/pl_PL: Fix int_curr_symbol.
+
+1998-01-26  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* nis/nis_cache.c: Include <unistd.h> for declaration of close.
+
+1998-01-06  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* stdio-common/test-popen.c: Include <errno.h>.
+
+	* sysdeps/unix/sysv/linux/if_index.c: Include <unistd.h> for
+	close.
+
+	* inet/getnetgrent_r.c: Include <errno.h>.
+
+	* db2/db/db_conv.c: Include <string.h> for memcpy.
+
+	* gmon/bb_exit_func.c: Include <string.h> instead of <strings.h>
+	so that memcpy is declared.
+
+	* iconv/iconv_open.c: Include <stdlib.h> for alloca.
+
+	* misc/init-misc.c: Remove unneeded inclusion of <errno.h>.
+
+1998-01-26  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* pwd/fgetpwent_r.c (__fgetpwent_r): Correctly handle buffer
+	overflow while reading line with fgets.
+	* grp/fgetgrent_r.c (__fgetgrent_r): Likewise.
+
+1998-01-27 00:46  Ulrich Drepper  <drepper@cygnus.com>
+
+	* sysdeps/unix/sysv/linux/bits/types.h (__ipc_pid_t): Change to
+	unsigned short, not short.
+	Reported by Andreas Jaeger.
+
+1998-01-06  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* sysdeps/unix/sysv/linux/mips/syscalls.list: Correct typo
+	(ccept->accept).
+
+	* sysdeps/generic/inttypes.h: Fix spelling.
+
+1998-01-04  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* sysdeps/unix/sysv/linux/arm/Dist: Add bits/mman.h.
+
+	* sysdeps/unix/sysv/linux/alpha/Dist: Add net/route.h.
+
+1998-01-27 00:30  Ulrich Drepper  <drepper@cygnus.com>
+
+	* stdio-common/printf.h (struct print_info): Add new bitfield is_char.
+	* stdio-common/printf-parse.h (parse_one_spec): Fill in is_char
+	field for hh modifier.
+	* stdio-common/vfprint.c: Use is_char field and do not depend in
+	is_short having the value 2.
+	Bug reported by Andreas Jaeger.
+
+1998-01-05  Andreas Jaeger  <aj@arthur.rhein-neckar.de>
+
+	* libio/freopen.c (freopen): Call _IO_old_freopen only if defined
+	PIC && DO_VERSIONING.
+
+1998-01-24  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
+
+	* Rules: Add rules for $(common-objpfx)dummy$o.
+
 1998-01-26  Richard Henderson  <rth@cygnus.com>
 
 	* sysdeps/unix/sysv/linux/alpha/bits/mman.h: Dyke out the
diff --git a/Rules b/Rules
index f50abd1248..90a518f866 100644
--- a/Rules
+++ b/Rules
@@ -1,4 +1,4 @@
-# Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+# Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98 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
@@ -71,7 +71,6 @@ define make-dummy-lib
 $(AR) cr$(verbose) $@ $<
 endef
 
-$(common-objpfx)dummy.o: $(common-objpfx)dummy.c; $(compile-command.c)
 $(common-objpfx)dummy.c:
 	rm -f $@
 	echo 'void __dummy__ (void) { }' > $@
@@ -162,6 +161,13 @@ endef
 object-suffixes-left := $(object-suffixes)
 include $(o-iterator)
 
+define o-iterator-doit
+$(common-objpfx)dummy$o: $(common-objpfx)dummy.c $(before-compile);
+	$$(compile-command.c)
+endef
+object-suffixes-left := $(object-suffixes)
+include $(o-iterator)
+
 ifndef libc.so-version
 # Undefine this because it can't work when we libc.so is unversioned.
 static-only-routines =
diff --git a/assert/assert.h b/assert/assert.h
index 3f0b55f866..ec54f64c05 100644
--- a/assert/assert.h
+++ b/assert/assert.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 94, 95, 96, 97, 98 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
@@ -80,9 +80,9 @@ __END_DECLS
 
 # ifdef	__USE_GNU
 #  define assert_perror(errnum)						      \
-  ((void) ((errnum) ? 0 : (__assert_perror_fail ((errnum),		      \
-						 __FILE__, __LINE__,	      \
-						 __ASSERT_FUNCTION), 0)))
+  ((void) (!(errnum) ? 0 : (__assert_perror_fail ((errnum),		      \
+						  __FILE__, __LINE__,	      \
+						  __ASSERT_FUNCTION), 0)))
 # endif
 
 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
diff --git a/config.make.in b/config.make.in
index 659ff409ce..500333f4b0 100644
--- a/config.make.in
+++ b/config.make.in
@@ -8,6 +8,7 @@ prefix = @prefix@
 exec_prefix = @exec_prefix@
 slibdir = @libc_cv_slibdir@
 sysconfdir = @libc_cv_sysconfdir@
+libexecdir = @libexecdir@
 rootsbindir = @libc_cv_rootsbindir@
 
 # If ldconfig exists.  This will go away as soon as `ldconfig' is available
diff --git a/db2/db/db_conv.c b/db2/db/db_conv.c
index c075df33fe..e9c4bf90bd 100644
--- a/db2/db/db_conv.c
+++ b/db2/db/db_conv.c
@@ -51,6 +51,7 @@ static const char sccsid[] = "@(#)db_conv.c	10.8 (Sleepycat) 1/8/98";
 #include <sys/types.h>
 
 #include <errno.h>
+#include <string.h>
 #endif
 
 #include "db_int.h"
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 84a76cfb4a..b984aa8f89 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -1,5 +1,5 @@
 /* Load a shared object at runtime, relocate it, and run its initializer.
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998 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
@@ -93,6 +93,13 @@ _dl_open (const char *file, int mode)
 	     between when _dl_object_relocation_scope returns and when we
 	     enter the dynamic linker's code (_dl_relocate_object).  */
 	  __typeof (_dl_relocate_object) *reloc = &_dl_relocate_object;
+
+	  /* GCC is very clever.  If we wouldn't add some magic it would
+	     simply optimize away our nice little variable `reloc' and we
+	     would result in a not working binary.  So let's swing the
+	     magic ward.  */
+	  asm ("" : "=r" (reloc) : "0" (reloc));
+
 	  (*reloc) (l, _dl_object_relocation_scope (l),
 		    (mode & RTLD_BINDING_MASK) == RTLD_LAZY);
 	  *_dl_global_scope_end = NULL;
diff --git a/elf/genrtldtbl.awk b/elf/genrtldtbl.awk
index f5656a2b44..63ada003f6 100644
--- a/elf/genrtldtbl.awk
+++ b/elf/genrtldtbl.awk
@@ -12,7 +12,7 @@ BEGIN {
 END {
   for (i = 0; i < count; ++i) {
     printf ("static struct r_search_path_elem rtld_search_dir%d =\n", i+1);
-    printf ("  { \"%s/\", %d, unknown, 0, unknown, ",
+    printf ("  { \"%s/\", %d, unknown, 0, nonexisting, ",
 	    dir[i], length (dir[i]) + 1);
     if (i== 0)
       printf ("NULL };\n");
diff --git a/elf/rtld.c b/elf/rtld.c
index e0d35216b6..aa40d42097 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -482,6 +482,10 @@ of this helper program; chances are you did not intend to run this program.\n",
   preloads = NULL;
   npreloads = 0;
 
+  /* Initialize the data structures for the search paths for shared
+     objects.  */
+  _dl_init_paths ();
+
   preloadlist = getenv ("LD_PRELOAD");
   if (preloadlist)
     {
@@ -595,10 +599,6 @@ of this helper program; chances are you did not intend to run this program.\n",
       assert (i == npreloads);
     }
 
-  /* Initialize the data structures for the search paths for shared
-     objects.  */
-  _dl_init_paths ();
-
   /* Load all the libraries specified by DT_NEEDED entries.  If LD_PRELOAD
      specified some libraries to load, these are inserted before the actual
      dependencies in the executable's searchlist for symbol resolution.  */
diff --git a/gmon/bb_exit_func.c b/gmon/bb_exit_func.c
index 53ddbfdbe9..032e4f68b2 100644
--- a/gmon/bb_exit_func.c
+++ b/gmon/bb_exit_func.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by David Mosberger (davidm@cs.arizona.edu).
 
@@ -24,7 +24,7 @@
 #include <sys/types.h>
 
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 
 /* structure emitted by -a */
 struct bb
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
index b142f908e6..9ac9dc19ef 100644
--- a/grp/fgetgrent_r.c
+++ b/grp/fgetgrent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996, 1997, 1998 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
@@ -61,12 +61,18 @@ __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
 
   do
     {
+      buffer[buflen] = '\xff';
       p = fgets (buffer, buflen, stream);
-      if (p == NULL)
+      if (p == NULL && feof (stream))
 	{
 	  *result = NULL;
 	  return errno;
 	}
+      if (p == NULL || buffer[buflen] != '\xff')
+	{
+	  *result = NULL;
+	  return errno = ERANGE;
+	}
 
       /* Skip leading blanks.  */
       while (isspace (*p))
diff --git a/iconv/iconv_open.c b/iconv/iconv_open.c
index bfff00d917..d178362ca7 100644
--- a/iconv/iconv_open.c
+++ b/iconv/iconv_open.c
@@ -1,5 +1,5 @@
 /* Get descriptor for character set conversion.
-   Copyright (C) 1997 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <iconv.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <gconv.h>
diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c
index d7a2b58b78..83e4c9ef57 100644
--- a/inet/getnetgrent_r.c
+++ b/inet/getnetgrent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 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
@@ -17,6 +17,7 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <bits/libc-lock.h>
+#include <errno.h>
 #include <netdb.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/libc.map b/libc.map
index af76e64227..593858fc2b 100644
--- a/libc.map
+++ b/libc.map
@@ -210,8 +210,8 @@ GLIBC_2.0 {
     getnetname; getopt; getopt_long; getopt_long_only; getpagesize;
     getpass; getpeername; getpgid; getpgrp; getpid; getppid; getpriority;
     getprotobyname; getprotobyname_r; getprotobynumber;
-    getprotobynumber_r; getprotoent; getprotoent_r; getpublickey; getpw;
-    getpwent; getpwent_r; getpwnam; getpwnam_r; getpwuid; getpwuid_r;
+    getprotobynumber_r; getprotoent; getprotoent_r; getpt; getpublickey;
+    getpw; getpwent; getpwent_r; getpwnam; getpwnam_r; getpwuid; getpwuid_r;
     getresgid; getresuid;
     getrlimit; getrlimit64; getrpcbyname; getrpcbyname_r; getrpcbynumber;
     getrpcbynumber_r; getrpcent; getrpcent_r; getrpcport; getrusage; gets;
@@ -221,7 +221,7 @@ GLIBC_2.0 {
     gettext; gettimeofday; getttyent; getttynam; getuid; getusershell;
     getutent; getutent_r; getutid; getutid_r; getutline; getutline_r;
     getutxent; getutxid; getutxline; getw; getwd; glob; glob_pattern_p;
-    globfree; gmtime; gmtime_r; group_member; gsignal; gtty;
+    globfree; gmtime; gmtime_r; grantpt; group_member; gsignal; gtty;
 
     # h*
     hasmntopt; hcreate; hcreate_r; hdestroy; hdestroy_r; herror;
@@ -305,9 +305,10 @@ GLIBC_2.0 {
     pthread_self; pthread_setcancelstate; pthread_setcanceltype;
     pthread_setschedparam;
 
-    ptrace; putc; putc_unlocked; putchar;
-    putchar_unlocked; putenv; putpwent; puts; putspent; pututline;
-    pututxline; putw; pvalloc;
+    ptrace; ptsname; ptsname_r;
+    putc; putc_unlocked; putchar; putchar_unlocked;
+    putenv; putpwent; puts; putspent; pututline; pututxline;
+    putw; pvalloc;
 
     # q*
     qecvt; qecvt_r; query_module; qfcvt; qfcvt_r; qgcvt; qsort; quotactl;
@@ -382,7 +383,7 @@ GLIBC_2.0 {
     twalk; tzset;
 
     # u*
-    ualarm; ulckpwdf; ulimit; umask; umount; uname; ungetc; unlink;
+    ualarm; ulckpwdf; ulimit; umask; umount; uname; ungetc; unlink; unlockpt;
     unsetenv; updwtmp; uselib; user2netname; usleep; ustat; utime; utimes;
     utmpname;
 
diff --git a/libio/freopen.c b/libio/freopen.c
index 808d8fab58..0452e7e6bb 100644
--- a/libio/freopen.c
+++ b/libio/freopen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU IO Library.
 
    This library is free software; you can redistribute it and/or
@@ -43,7 +43,7 @@ freopen (filename, mode, fp)
     return NULL;
   _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
   _IO_flockfile (fp);
-#ifdef PIC
+#if defined PIC && DO_VERSIONING
   if (&_IO_stdin_used == NULL)
     /* If the shared C library is used by the application binary which
        was linked against the older version of libio, we just use the
diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c
index 9c591f6271..78a9cd92ac 100644
--- a/locale/programs/ld-collate.c
+++ b/locale/programs/ld-collate.c
@@ -630,7 +630,7 @@ Computing table size for collation information might take a while..."),
     extra2[cnt] = SWAPU32 (extra2[cnt]);
 
   /* We need a simple hashing table to get a collation-element->chars
-     mapping.  We again use internal hasing using a secondary hashing
+     mapping.  We again use internal hashing using a secondary hashing
      function.
 
      Each string has an associate hashing value V, computed by a
diff --git a/localedata/locales/pl_PL b/localedata/locales/pl_PL
index 0ad8f83a99..587811004c 100644
--- a/localedata/locales/pl_PL
+++ b/localedata/locales/pl_PL
@@ -2095,7 +2095,7 @@ noexpr  "<<(><n><N><)/>><.><*>"
 END LC_MESSAGES
 
 LC_MONETARY
-int_curr_symbol           "<P><L><N><SP>"
+int_curr_symbol           "<P><L><Z><SP>"
 currency_symbol           "<Z><l//>"
 mon_decimal_point         "<,>"
 mon_thousands_sep         "<.>"
diff --git a/localedata/locales/ru_RU b/localedata/locales/ru_RU
index 252a10154d..9da6982624 100644
--- a/localedata/locales/ru_RU
+++ b/localedata/locales/ru_RU
@@ -2091,7 +2091,7 @@ order_end
 END LC_COLLATE
 
 LC_MESSAGES
-yesexpr "<<(><D=><d=><Y><Y><)/>><.><*>"
+yesexpr "<<(><D=><d=><Y><y><)/>><.><*>"
 noexpr  "<<(><N=><n=><N><n><)/>><.><*>"
 END LC_MESSAGES
 
diff --git a/login/Makefile b/login/Makefile
index 3842b2f4af..04c6eeb8a4 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998 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
@@ -25,10 +25,14 @@ subdir	:= login
 headers	:= utmp.h bits/utmp.h utmpx.h bits/utmpx.h lastlog.h pty.h
 
 routines := getutent getutent_r getutid getutline getutid_r getutline_r \
-	    utmp_file utmp_daemon utmpname updwtmp
+	    utmp_file utmp_daemon utmpname updwtmp \
+	    getpt grantpt unlockpt ptsname
 
-others = utmpd utmpdump
+CFLAGS-grantpt.c = -DLIBEXECDIR='"$(libexecdir)"'
+
+others = utmpd utmpdump pt_chown
 install-sbin = utmpd
+install-others = $(inst_libexecdir)/pt_chown
 utmpd-routines := connection database error request xtmp
 extra-objs := $(utmpd-routines:=.o)
 
@@ -42,11 +46,15 @@ vpath %.c programs
 extra-libs      := libutil
 extra-libs-others := $(extra-libs)
 
-libutil-routines:= login login_tty logout logwtmp pty
+libutil-routines:= login login_tty logout logwtmp openpty forkpty
 libutil-map	:= libutil.map
 
 include ../Rules
 
+# pt_chown needs to be setuid root.
+$(inst_libexecdir)/pt_chown: $(objpfx)pt_chown
+	$(INSTALL) -m 4755 -o root $< $@
+
 $(objpfx)utmpd: $(utmpd-routines:%=$(objpfx)%.o)
 
 # Depend on libc.so so a DT_NEEDED is generated in the shared objects.
diff --git a/login/forkpty.c b/login/forkpty.c
new file mode 100644
index 0000000000..e0e3cce9f9
--- /dev/null
+++ b/login/forkpty.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <sys/types.h>
+#include <termios.h>
+#include <unistd.h>
+#include <utmp.h>
+#include <pty.h>
+
+int
+forkpty (amaster, name, termp, winp)
+     int *amaster;
+     char *name;
+     struct termios *termp;
+     struct winsize *winp;
+{
+  int master, slave, pid;
+
+  if (openpty (&master, &slave, name, termp, winp) == -1)
+    return -1;
+
+  switch (pid = fork ())
+    {
+    case -1:
+      return -1;
+    case 0:
+      /* Child.  */
+      close (master);
+      if (login_tty (slave))
+	_exit (1);
+
+      return 0;
+    default:
+      /* Parent.  */
+      *amaster = master;
+      close (slave);
+
+      return pid;
+    }
+}
diff --git a/login/openpty.c b/login/openpty.c
new file mode 100644
index 0000000000..12e82072bc
--- /dev/null
+++ b/login/openpty.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <fcntl.h>
+#include <pty.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "pty-internal.h"
+
+int
+openpty (pmast, pslave, pname, tio, wins)
+     int *pmast;
+     int *pslave;
+     char *pname;
+     struct termios *tio;
+     struct winsize *wins;
+{
+  int pfd, tfd;
+  char name[PTYNAMELEN];
+
+  pfd = getpt ();
+  if (pfd == -1)
+    return -1;
+
+  if (grantpt (pfd))
+    goto bail;
+
+  if (unlockpt (pfd))
+    goto bail;
+
+  if (!ptsname_r (pfd, name, PTYNAMELEN))
+    goto bail;
+
+  tfd = open (name, O_RDWR);
+  if (tfd == -1)
+    goto bail;
+
+  /* XXX Should we ignore errors here?  */
+  if(tio)
+    tcsetattr (tfd, TCSAFLUSH, tio);
+  if (wins)
+    ioctl (tfd, TIOCSWINSZ, wins);
+
+  *pmast = pfd;
+  *pslave = tfd;
+  if (pname != NULL)
+    strcpy (pname, name);
+  return 0;
+
+bail:
+  close (pfd);
+  return -1;
+}
diff --git a/login/programs/pt_chown.c b/login/programs/pt_chown.c
new file mode 100644
index 0000000000..dbf79fc6ad
--- /dev/null
+++ b/login/programs/pt_chown.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by C. Scott Ananian <cananian@alumni.princeton.edu>, 1998.
+
+   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.  */
+
+/* pt_chmod.c ... securely implement grantpt in user-land.  */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <grp.h>
+
+#include "pty-internal.h"
+#define Str(x) _Str(x)
+#define _Str(x) #x
+
+void
+usage (void)
+{
+  fprintf (stderr, _("usage: pt_chown FD>&%s\n"
+		     "This program is used internally by grantpt(3).\n"),
+	   Str (PTY_FD));
+  exit (0);
+}
+
+void
+bad_installation (void)
+{
+  fputs (_("pt_chown: installation problem: "
+	   "This program needs to be setuid root.\n"), stderr);
+  exit (FAIL_EXEC);
+}
+
+int
+main (int argc, char **argv)
+{
+  struct group *grp;
+  struct stat s;
+  char *pty;
+  gid_t gid;
+  uid_t uid;
+
+  if (argc != 1)
+    usage ();
+  if (geteuid () != 0)
+    bad_installation ();
+
+  grp = getgrnam (TTY_GROUP);
+  gid = grp ? grp->gr_gid : getgid ();
+  uid = getuid ();
+
+  /* Check that fd is a valid pty master -- call ptsname().  */
+  pty = ptsname (PTY_FD);
+  if (pty == NULL)
+    return errno == EBADF ? FAIL_EBADF : FAIL_EINVAL;
+  close (PTY_FD);
+
+  /* Check that target file is a character device.  */
+  if (stat (pty, &s))
+    return FAIL_EINVAL; /* This should only fail if pty doesn't exist.  */
+  if (!S_ISCHR (s.st_mode))
+    return FAIL_EINVAL;
+
+  if (chmod (pty, 0620))
+    return FAIL_EACCES;  /* XXX: Probably not true. */
+
+  if (chown (pty, uid, gid))
+    return FAIL_EACCES;
+
+  return 0;
+}
diff --git a/login/pty-internal.h b/login/pty-internal.h
new file mode 100644
index 0000000000..c1858861ec
--- /dev/null
+++ b/login/pty-internal.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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.  */
+
+/* Internal constants used by the pseudoterminal handling code. */
+
+#ifndef _PTY_INTERNAL_H
+#define _PTY_INTERNAL_H	1
+
+/* Length of a buffer to hold a pty name. */
+#define PTYNAMELEN 15   /* "/dev/pts/65535$" */
+
+/* Which group should pty slaves belong to: */
+#define TTY_GROUP "tty"
+
+/* Communication between grantpt and pt_chown. */
+#define PTY_FD 3
+enum  /* failure modes */
+{
+  FAIL_EBADF = 1,
+  FAIL_EINVAL,
+  FAIL_EACCES,
+  FAIL_EXEC
+};
+
+#endif
diff --git a/login/utmp_file.c b/login/utmp_file.c
index bea63644f7..d25dcb8600 100644
--- a/login/utmp_file.c
+++ b/login/utmp_file.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>
    and Paul Janzen <pcj@primenet.com>, 1996.
@@ -390,12 +390,12 @@ pututline_file (const struct utmp *data)
     }
 
   /* Write the new data.  */
-  if (write (file_fd, data, sizeof (struct utmp)) != sizeof (struct utmp)
+  if (write (file_fd, data, sizeof (struct utmp)) != sizeof (struct utmp))
+    {
       /* If we appended a new record this is only partially written.
 	 Remove it.  */
-      && found < 0)
-    {
-      (void) ftruncate (file_fd, file_offset);
+      if (found < 0)
+	(void) ftruncate (file_fd, file_offset);
       pbuf = NULL;
     }
   else
diff --git a/manual/Makefile b/manual/Makefile
index 34f894e49e..c528493801 100644
--- a/manual/Makefile
+++ b/manual/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+# Copyright (C) 1992, 93, 94, 95, 96, 97, 98 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
@@ -149,12 +149,14 @@ realclean: distclean
 
 .PHONY: install subdir_install installdirs install-data
 install-data subdir_install: install
+ifneq ($(strip $(MAKEINFO)),)
 install: $(inst_infodir)/libc.info dir-add.info
 	@if $(SHELL) -c '$(INSTALL_INFO) --version' >/dev/null 2>&1; then \
 	  test -f $(inst_infodir)/dir || cp dir $(inst_infodir);\
 	 $(INSTALL_INFO) --info-dir=$(inst_infodir) $(inst_infodir)/libc.info;\
 	 $(INSTALL_INFO) --info-dir=$(inst_infodir) dir-add.info;\
 	else : ; fi
+endif
 # Catchall implicit rule for other installation targets from the parent.
 install-%: ;
 
diff --git a/misc/init-misc.c b/misc/init-misc.c
index b62f3921ad..9bcd6c7563 100644
--- a/misc/init-misc.c
+++ b/misc/init-misc.c
@@ -1,5 +1,5 @@
 /* Define and initialize `__progname' et. al.
-   Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1995, 1996, 1997, 1998 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
@@ -18,7 +18,6 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <string.h>
-#include <errno.h>
 
 char *__progname_full = (char *) "";
 char *__progname = (char *) "";
diff --git a/nis/nis_cache.c b/nis/nis_cache.c
index a0e1130077..26cac675a5 100644
--- a/nis/nis_cache.c
+++ b/nis/nis_cache.c
@@ -17,6 +17,8 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA. */
 
+#include <string.h>
+#include <unistd.h>
 #include <rpcsvc/nis.h>
 #include "nis_intern.h"
 
diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
index dab1b5e566..ca5abc4d2c 100644
--- a/nis/nss_compat/compat-grp.c
+++ b/nis/nss_compat/compat-grp.c
@@ -263,6 +263,14 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
 	      ent->nis = 0;
 	      return NSS_STATUS_UNAVAIL;
 	    }
+
+	  if ( buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  save_oldkey = ent->oldkey;
 	  save_oldlen = ent->oldkeylen;
 	  save_nis_first = TRUE;
@@ -280,6 +288,13 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
+	  if ( buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  save_oldkey = ent->oldkey;
 	  save_oldlen = ent->oldkeylen;
 	  save_nis_first = FALSE;
@@ -287,7 +302,7 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
 	  ent->oldkeylen = outkeylen;
 	}
 
-      /* Copy the found data to our buffer  */
+      /* Copy the found data to our buffer...  */
       p = strncpy (buffer, outval, buflen);
 
       /* ...and free the data.  */
@@ -427,8 +442,17 @@ getgrnam_plusgroup (const char *name, struct group *result, char *buffer,
 		    &outval, &outvallen) != YPERR_SUCCESS)
 	return NSS_STATUS_NOTFOUND;
 
-      p = strncpy (buffer, outval,
-                   buflen < (size_t) outvallen ? buflen : (size_t) outvallen);
+      if (buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+
+      /* Copy the found data to our buffer...  */
+      p = strncpy (buffer, outval, buflen);
+
+      /* ... and free the data.  */
       free (outval);
       while (isspace (*p))
         ++p;
@@ -758,9 +782,20 @@ getgrgid_plusgroup (gid_t gid, struct group *result, char *buffer,
 	  *errnop = errno;
 	  return NSS_STATUS_TRYAGAIN;
 	}
-      p = strncpy (buffer, outval,
-                   buflen < (size_t) outvallen ? buflen : (size_t) outvallen);
+
+      if (buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+
+      /* Copy the found data to our buffer...  */
+      p = strncpy (buffer, outval, buflen);
+
+      /* ... and free the data.  */
       free (outval);
+
       while (isspace (*p))
         p++;
       parse_res = _nss_files_parse_grent (p, result, data, buflen, errnop);
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
index 5bfff17ca5..eec2634f3a 100644
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -393,7 +393,7 @@ getpwent_next_nis_netgr (const char *name, struct passwd *result, ent_t *ent,
       if (domain != NULL && strcmp (ypdomain, domain) != 0)
 	continue;
 
-      /* If name != NULL, we are called from getpwnam */
+      /* If name != NULL, we are called from getpwnam.  */
       if (name != NULL)
 	if (strcmp (user, name) != 0)
 	  continue;
@@ -406,12 +406,21 @@ getpwent_next_nis_netgr (const char *name, struct passwd *result, ent_t *ent,
       p2len = pwd_need_buflen (&ent->pwd);
       if (p2len > buflen)
 	{
+	  free (outval);
 	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
       p2 = buffer + (buflen - p2len);
       buflen -= p2len;
+
+      if (buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
       p = strncpy (buffer, outval, buflen);
+
       while (isspace (*p))
 	p++;
       free (outval);
@@ -650,6 +659,13 @@ getpwent_next_nis (struct passwd *result, ent_t *ent, char *buffer,
 	      return NSS_STATUS_UNAVAIL;
 	    }
 
+	  if (buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  saved_first = TRUE;
 	  saved_oldkey = ent->oldkey;
 	  saved_oldlen = ent->oldkeylen;
@@ -668,6 +684,13 @@ getpwent_next_nis (struct passwd *result, ent_t *ent, char *buffer,
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
+	  if (buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  saved_first = FALSE;
 	  saved_oldkey = ent->oldkey;
 	  saved_oldlen = ent->oldkeylen;
@@ -769,9 +792,13 @@ getpwnam_plususer (const char *name, struct passwd *result, char *buffer,
 		    &outval, &outvallen) != YPERR_SUCCESS)
 	return NSS_STATUS_NOTFOUND;
 
-      ptr = strncpy (buffer, outval, buflen < (size_t) outvallen ?
-		     buflen : (size_t) outvallen);
-      buffer[buflen < (size_t) outvallen ? buflen : (size_t) outvallen] = '\0';
+      if (buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+      ptr = strncpy (buffer, outval, buflen);
       free (outval);
       while (isspace (*ptr))
 	ptr++;
@@ -1259,10 +1286,17 @@ getpwuid_plususer (uid_t uid, struct passwd *result, char *buffer,
 	  *errnop = errno;
 	  return NSS_STATUS_TRYAGAIN;
 	}
-      ptr = strncpy (buffer, outval, buflen < (size_t) outvallen ?
-		     buflen : (size_t) outvallen);
-      buffer[buflen < (size_t) outvallen ? buflen : (size_t) outvallen] = '\0';
+
+      if ( buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+
+      ptr = strncpy (buffer, outval, buflen);
       free (outval);
+
       while (isspace (*ptr))
 	ptr++;
       parse_res = _nss_files_parse_pwent (ptr, result, data, buflen, errnop);
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index 816e9c1f0a..1d4216393a 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -359,11 +359,18 @@ getspent_next_nis_netgr (const char *name, struct spwd *result, ent_t *ent,
       p2len = spwd_need_buflen (&ent->pwd);
       if (p2len > buflen)
 	{
+	  free (outval);
 	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
       p2 = buffer + (buflen - p2len);
       buflen -= p2len;
+      if (buflen < ((size_t) outval + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
       p = strncpy (buffer, outval, buflen);
       while (isspace (*p))
 	p++;
@@ -601,6 +608,14 @@ getspent_next_nis (struct spwd *result, ent_t *ent,
 	      give_spwd_free (&ent->pwd);
 	      return NSS_STATUS_UNAVAIL;
 	    }
+
+	  if (buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  saved_first = TRUE;
 	  saved_oldkey = ent->oldkey;
 	  saved_oldlen = ent->oldkeylen;
@@ -619,6 +634,13 @@ getspent_next_nis (struct spwd *result, ent_t *ent,
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
+	  if (buflen < ((size_t) outvallen + 1))
+	    {
+	      free (outval);
+	      *errnop = ERANGE;
+	      return NSS_STATUS_TRYAGAIN;
+	    }
+
 	  saved_first = FALSE;
 	  saved_oldkey = ent->oldkey;
 	  saved_oldlen = ent->oldkeylen;
@@ -720,9 +742,14 @@ getspnam_plususer (const char *name, struct spwd *result, char *buffer,
 		    &outval, &outvallen)  != YPERR_SUCCESS)
 	return NSS_STATUS_NOTFOUND;
 
-      ptr = strncpy (buffer, outval, buflen < (size_t) outvallen ?
-		     buflen : (size_t) outvallen);
-      buffer[buflen < (size_t) outvallen ? buflen : (size_t) outvallen] = '\0';
+      if (buflen < ((size_t) outvallen + 1))
+	{
+	  free (outval);
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+
+      ptr = strncpy (buffer, outval, buflen);
       free (outval);
       while (isspace (*ptr))
         ptr++;
diff --git a/nss/Makefile b/nss/Makefile
index 904d3ec423..e0fceee93e 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998 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
@@ -36,6 +36,8 @@ routines		= nsswitch $(addsuffix -lookup,$(databases))
 databases		= proto service hosts network grp pwd rpc ethers \
 			  spwd netgrp key alias
 
+tests			= test-netdb
+
 include ../Makeconfig
 
 # Specify rules for the nss_* modules.  We have some services.
diff --git a/nss/test-netdb.c b/nss/test-netdb.c
new file mode 100644
index 0000000000..918bbeb7c3
--- /dev/null
+++ b/nss/test-netdb.c
@@ -0,0 +1,349 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998.
+
+   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.  */
+
+/*
+  Testing of some network related lookup functions.
+  The system databases looked up are:
+  - /etc/services
+  - /etc/hosts
+  - /etc/networks
+  - /etc/protocols
+  - /etc/rpc
+  The tests try to be fairly generic and simple so that they work on
+  every possible setup (and might therefore not detect some possible
+  errors).
+*/
+
+#include <netdb.h>
+#include <rpc/netdb.h>
+#include <stdio.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+/*
+  The following define is neccessary for glibc 2.0.6
+*/
+#ifndef INET6_ADDRSTRLEN
+# define INET6_ADDRSTRLEN 46
+#endif
+
+int error_count;
+
+void
+output_servent (const char *call, struct servent *sptr)
+{
+  char **pptr;
+
+  if (sptr == NULL)
+    printf ("Call: %s returned NULL\n", call);
+  else
+    {
+      printf ("Call: %s, returned: s_name: %s, s_port: %d, s_proto: %s\n",
+	      call, sptr->s_name, ntohs(sptr->s_port), sptr->s_proto);
+      for (pptr = sptr->s_aliases; *pptr != NULL; pptr++)
+	printf ("  alias: %s\n", *pptr);
+    }
+}
+
+
+void
+test_services (void)
+{
+  struct servent *sptr;
+
+  sptr = getservbyname ("domain", "tcp");
+  output_servent ("getservbyname (\"domain\", \"tcp\")", sptr);
+
+  sptr = getservbyname ("domain", "udp");
+  output_servent ("getservbyname (\"domain\", \"udp\")", sptr);
+
+  sptr = getservbyname ("domain", NULL);
+  output_servent ("getservbyname (\"domain\", NULL)", sptr);
+
+  sptr = getservbyname ("not-existant", NULL);
+  output_servent ("getservbyname (\"not-existant\", NULL)", sptr);
+
+  sptr = getservbyport (htons(53), "tcp");
+  output_servent ("getservbyport (htons(53), \"tcp\")", sptr);
+
+  sptr = getservbyport (htons(53), NULL);
+  output_servent ("getservbyport (htons(53), NULL)", sptr);
+
+  sptr = getservbyport (htons(1), "udp"); /* shouldn't exist */
+  output_servent ("getservbyport (htons(1), \"udp\")", sptr);
+
+  setservent (0);
+  do
+    {
+      sptr = getservent ();
+      output_servent ("getservent ()", sptr);
+    }
+  while (sptr != NULL);
+  endservent ();
+}
+
+
+void
+output_hostent (const char *call, struct hostent *hptr)
+{
+  int i;
+  char **pptr;
+  char buf[INET6_ADDRSTRLEN];
+
+  if (hptr == NULL)
+    printf ("Call: %s returned NULL\n", call);
+  else
+    {
+      printf ("Call: %s returned: name: %s, addr_type: %d\n",
+	      call, hptr->h_name, hptr->h_addrtype);
+      for (pptr = hptr->h_aliases; *pptr != NULL; pptr++)
+	printf ("  alias: %s\n", *pptr);
+
+      for (pptr = hptr->h_addr_list; *pptr != NULL; pptr++)
+	printf ("  ip: %s\n",
+		inet_ntop (hptr->h_addrtype, *pptr, buf, sizeof (buf)));
+    }
+}
+
+void
+test_hosts (void)
+{
+  struct hostent *hptr1, *hptr2;
+  char name[MAXHOSTNAMELEN];
+  size_t namelen = sizeof(name);
+  struct in_addr ip;
+
+  hptr1 = gethostbyname ("localhost");
+  hptr2 = gethostbyname ("LocalHost");
+  if (hptr1 != NULL || hptr2 != NULL)
+    {
+      if (hptr1 == NULL)
+	{
+	  printf ("localhost not found - but LocalHost found:-(\n");
+	  ++error_count;
+	}
+      else if (hptr2 == NULL)
+	{
+	  printf ("LocalHost not found - but localhost found:-(\n");
+	  ++error_count;
+	}
+      else if (strcmp (hptr1->h_name, hptr2->h_name) != 0)
+	{
+	  printf ("localhost and LocalHost have different canoncial name\n");
+	  printf ("gethostbyname (\"localhost\")->%s\n", hptr1->h_name);
+	  printf ("gethostbyname (\"LocalHost\")->%s\n", hptr2->h_name);
+	  ++error_count;
+	}
+      else
+	output_hostent ("gethostbyname(\"localhost\")", hptr1);
+    }
+
+
+  if (gethostname (name, namelen) == 0)
+    {
+      printf ("Hostname: %s\n", name);
+      hptr1 = gethostbyname (name);
+      output_hostent ("gethostbyname (gethostname(...))", hptr1);
+    }
+
+  ip.s_addr = htonl (INADDR_LOOPBACK);
+  hptr1 = gethostbyaddr ((char *)&ip, sizeof(ip), AF_INET);
+  if (hptr1 != NULL)
+    {
+      printf ("official name of 127.0.0.1: %s\n", hptr1->h_name);
+    }
+
+  sethostent (0);
+  do
+    {
+      hptr1 = gethostent ();
+      output_hostent ("gethostent ()", hptr1);
+    }
+  while (hptr1 != NULL);
+  endhostent ();
+
+}
+
+
+void
+output_netent (const char *call, struct netent *nptr)
+{
+  char **pptr;
+
+  if (nptr == NULL)
+    printf ("Call: %s returned NULL\n", call);
+  else
+    {
+      struct in_addr ip;
+
+      ip.s_addr = htonl(nptr->n_net);
+      printf ("Call: %s, returned: n_name: %s, network_number: %s\n",
+	      call, nptr->n_name, inet_ntoa (ip));
+
+      for (pptr = nptr->n_aliases; *pptr != NULL; pptr++)
+	printf ("  alias: %s\n", *pptr);
+    }
+}
+
+void
+test_network (void)
+{
+  struct netent *nptr;
+  u_int32_t ip;
+
+  /*
+    this test needs the following line in /etc/networks:
+     loopback        127.0.0.0
+  */
+  nptr = getnetbyname ("loopback");
+  output_netent ("getnetbyname (\"loopback\")",nptr);
+
+  ip = inet_network ("127.0.0.0");
+  nptr = getnetbyaddr (ip, AF_INET);
+  output_netent ("getnetbyaddr (inet_network (\"127.0.0.0\"), AF_INET)",nptr);
+
+  setnetent (0);
+  do
+    {
+      nptr = getnetent ();
+      output_netent ("getnetent ()", nptr);
+    }
+  while (nptr != NULL);
+  endnetent ();
+}
+
+
+void
+output_protoent (const char *call, struct protoent *prptr)
+{
+  char **pptr;
+
+  if (prptr == NULL)
+    printf ("Call: %s returned NULL\n", call);
+  else
+    {
+      printf ("Call: %s, returned: p_name: %s, p_proto: %d\n",
+	      call, prptr->p_name, prptr->p_proto);
+      for (pptr = prptr->p_aliases; *pptr != NULL; pptr++)
+	printf ("  alias: %s\n", *pptr);
+    }
+}
+
+
+void
+test_protocols (void)
+{
+  struct protoent *prptr;
+
+  prptr = getprotobyname ("IP");
+  output_protoent ("getprotobyname (\"IP\")", prptr);
+
+  prptr = getprotobynumber (1);
+  output_protoent ("getprotobynumber (1)", prptr);
+
+  setprotoent (0);
+  do
+    {
+      prptr = getprotoent ();
+      output_protoent ("getprotoent ()", prptr);
+    }
+  while (prptr != NULL);
+  endprotoent ();
+}
+
+
+void
+output_rpcent (const char *call, struct rpcent *rptr)
+{
+  char **pptr;
+
+  if (rptr == NULL)
+    printf ("Call: %s returned NULL\n", call);
+  else
+    {
+      printf ("Call: %s, returned: r_name: %s, r_number: %d\n",
+		call, rptr->r_name, rptr->r_number);
+      for (pptr = rptr->r_aliases; *pptr != NULL; pptr++)
+	printf ("  alias: %s\n", *pptr);
+    }
+}
+
+void
+test_rpc (void)
+{
+  struct rpcent *rptr;
+
+  rptr = getrpcbyname ("portmap");
+  output_rpcent ("getrpcyname (\"portmap\")", rptr);
+
+  rptr = getrpcbynumber (100000);
+  output_rpcent ("getrpcbynumber (100000)", rptr);
+
+  setrpcent (0);
+  do
+    {
+      rptr = getrpcent ();
+      output_rpcent ("getrpcent ()", rptr);
+    }
+  while (rptr != NULL);
+  endrpcent ();
+}
+
+/*
+  Override /etc/nsswitch.conf for this program.
+  This is mainly useful for developers
+*/
+void
+setdb (const char *dbname)
+{
+  if (strcmp ("db", dbname))
+      {
+	/*
+	  db is not implemented for hosts, networks
+	*/
+	__nss_configure_lookup ("hosts", dbname);
+	__nss_configure_lookup ("networks", dbname);
+      }
+  __nss_configure_lookup ("protocols", dbname);
+  __nss_configure_lookup ("rpc", dbname);
+  __nss_configure_lookup ("services", dbname);
+}
+
+
+int
+main (void)
+{
+  /*
+    setdb ("db");
+  */
+  test_hosts ();
+  test_network ();
+  test_protocols ();
+  test_rpc ();
+  test_services ();
+
+  if (error_count)
+    printf ("\n %d errors occured!\n", error_count);
+  else
+    printf ("No visible errors occured!\n");
+
+  exit (error_count);
+}
diff --git a/include/cpio.h b/posix/cpio.h
index 0364e8af80..0364e8af80 100644
--- a/include/cpio.h
+++ b/posix/cpio.h
diff --git a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c
index 7699901177..1aa70bffb5 100644
--- a/pwd/fgetpwent_r.c
+++ b/pwd/fgetpwent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996, 1997, 1998 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
@@ -74,12 +74,18 @@ __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer,
 
   do
     {
+      buffer[buflen] = '\xff';
       p = fgets (buffer, buflen, stream);
-      if (p == NULL)
+      if (p == NULL && feof (stream))
 	{
 	  *result = NULL;
 	  return errno;
 	}
+      if (p == NULL || buffer[buflen] != '\xff')
+	{
+	  *result = NULL;
+	  return errno = ERANGE;
+	}
 
       /* Skip leading blanks.  */
       while (isspace (*p))
diff --git a/signal/signal.h b/signal/signal.h
index 864a49b6e1..015f0f0b93 100644
--- a/signal/signal.h
+++ b/signal/signal.h
@@ -268,8 +268,8 @@ extern int sigqueue __P ((__pid_t __pid, int __sig,
 
 /* Names of the signals.  This variable exists only for compatibility.
    Use `strsignal' instead (see <string.h>).  */
-extern __const char *__const _sys_siglist[_NSIG];
-extern __const char *__const sys_siglist[_NSIG];
+extern __const char *__const _sys_siglist[_NSIG + 1];
+extern __const char *__const sys_siglist[_NSIG + 1];
 
 /* Structure passed to `sigvec'.  */
 struct sigvec
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index 30f381320e..036b3b4dfe 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -1,5 +1,5 @@
 /* Internal header for parsing printf format strings.
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of th GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -268,6 +268,7 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
   spec->info.is_long_double = 0;
   spec->info.is_short = 0;
   spec->info.is_long = 0;
+  spec->info.is_char = 0;
 
   if (*format == L_('h') || *format == L_('l') || *format == L_('L') ||
       *format == L_('Z') || *format == L_('q'))
@@ -278,7 +279,10 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 	if (spec->info.is_short == 0)
 	  spec->info.is_short = 1;
 	else
-	  spec->info.is_short = 2;
+	  {
+	    spec->info.is_short = 0;
+	    spec->info.is_char = 1;
+	  }
 	break;
       case L_('l'):
 	/* int's are long int's.  */
@@ -329,6 +333,8 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 	    spec->data_arg_type = PA_INT|PA_FLAG_LONG;
 	  else if (spec->info.is_short)
 	    spec->data_arg_type = PA_INT|PA_FLAG_SHORT;
+	  else if (spec->info.is_char)
+	    spec->data_arg_type = PA_CHAR;
 	  else
 	    spec->data_arg_type = PA_INT;
 	  break;
diff --git a/stdio-common/printf.h b/stdio-common/printf.h
index c49172b88c..8b3b4eb967 100644
--- a/stdio-common/printf.h
+++ b/stdio-common/printf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 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
@@ -44,6 +44,7 @@ struct printf_info
   unsigned int showsign:1;	/* + flag.  */
   unsigned int group:1;		/* ' flag.  */
   unsigned int extra:1;		/* For special use.  */
+  unsigned int is_char:1;	/* hh flag.  */
   wchar_t pad;			/* Padding character.  */
 };
 
diff --git a/stdio-common/test-popen.c b/stdio-common/test-popen.c
index b13a1c2542..aced45d5c9 100644
--- a/stdio-common/test-popen.c
+++ b/stdio-common/test-popen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998 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,7 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -26,9 +26,10 @@ write_data (FILE *stream)
   int i;
   for (i=0; i<100; i++)
     fprintf (stream, "%d\n", i);
-  if (ferror (stream))  {
-    fprintf (stderr, "Output to stream failed.\n");
-    exit (1);
+  if (ferror (stream))
+    {
+      fprintf (stderr, "Output to stream failed.\n");
+      exit (1);
     }
 }
 
diff --git a/stdio-common/tiformat.c b/stdio-common/tiformat.c
index 541ea43a0c..bce47665a7 100644
--- a/stdio-common/tiformat.c
+++ b/stdio-common/tiformat.c
@@ -9,7 +9,7 @@ typedef struct {
   const char *format_string;
 } sprint_int_type;
 
-sprint_int_type sprint_ints[] = 
+sprint_int_type sprint_ints[] =
 {
   {__LINE__, 0x000838d2,	"838d2", "%.4x"},
   {__LINE__, 0x0063be46,	"63BE46", "%-6X"},
@@ -5022,6 +5022,9 @@ sprint_int_type sprint_ints[] =
   {__LINE__, 0000123456,	"00123456", "%#.8o"},
   {__LINE__, 0000123456,	"  00123456", "%#10.8o"},
   {__LINE__, 0x00000123,	"0x00123", "%#07x"},
+  {__LINE__, 0x00000000,	"", "%#.0d"},
+  {__LINE__, 0x00000000,	"", "%#.0x"},
+  {__LINE__, 0x00000000,	"0", "%#.0o"},
 
   {0},
 };
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index 4abee7ed91..e6c2df25d6 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98 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
@@ -492,10 +492,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	  long int signed_number;					      \
 									      \
 	  if (fspec == NULL)						      \
-	    if (is_long)						      \
-	      signed_number = va_arg (ap, long int);			      \
-	    else  /* `char' and `short int' will be promoted to `int'.  */    \
-	      signed_number = va_arg (ap, int);				      \
+	    {								      \
+	      if (is_long)						      \
+		signed_number = va_arg (ap, long int);			      \
+	      else  /* `char' and `short int' will be promoted to `int'.  */  \
+		signed_number = va_arg (ap, int);			      \
+	    }								      \
 	  else								      \
 	    if (is_long)						      \
 	      signed_number = args_value[fspec->data_arg].pa_long_int;	      \
@@ -550,9 +552,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	    pad = ' ';							      \
 									      \
 	  /* If the precision is 0 and the number is 0 nothing has to	      \
-	     be written for the number.  */				      \
+	     be written for the number, except for the 'o' format in	      \
+	     alternate form.  */					      \
 	  if (prec == 0 && number.longlong == 0)			      \
-	    string = workend;						      \
+	    {								      \
+	      string = workend;						      \
+	      if (base == 8 && alt)					      \
+		*string-- = '0';					      \
+	    }								      \
 	  else								      \
 	    {								      \
 	      /* Put the number in WORK.  */				      \
@@ -569,12 +576,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       else								      \
 	{								      \
 	  if (fspec == NULL)						      \
-	    if (is_long)						      \
-	      number.word = va_arg (ap, unsigned long int);		      \
-	    else if (!is_short)						      \
-	      number.word = va_arg (ap, unsigned int);			      \
-	    else							      \
-	      number.word = (unsigned short int) va_arg (ap, unsigned int);   \
+	    {								      \
+	      if (is_long)						      \
+		number.word = va_arg (ap, unsigned long int);		      \
+	      else if (!is_short)					      \
+		number.word = va_arg (ap, unsigned int);		      \
+	      else							      \
+		number.word = (unsigned short int) va_arg (ap, unsigned int); \
+	    }								      \
 	  else								      \
 	    if (is_long)						      \
 	      number.word = args_value[fspec->data_arg].pa_u_long_int;	      \
@@ -597,9 +606,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	    pad = ' ';							      \
 									      \
 	  /* If the precision is 0 and the number is 0 nothing has to	      \
-	     be written for the number.  */				      \
+	     be written for the number, except for the 'o' format in	      \
+	     alternate form.  */					      \
 	  if (prec == 0 && number.word == 0)				      \
-	    string = workend;						      \
+	    {								      \
+	      string = workend;						      \
+	      if (base == 8 && alt)					      \
+		*string-- = '0';					      \
+	    }								      \
 	  else								      \
 	    {								      \
 	      /* Put the number in WORK.  */				      \
@@ -926,14 +940,16 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
     LABEL (form_number):						      \
       /* Answer the count of characters written.  */			      \
       if (fspec == NULL)						      \
-	if (is_longlong)						      \
-	  *(long long int *) va_arg (ap, void *) = done;		      \
-	else if (is_long)						      \
-	  *(long int *) va_arg (ap, void *) = done;			      \
-	else if (!is_short)						      \
-	  *(int *) va_arg (ap, void *) = done;				      \
-	else								      \
-	  *(short int *) va_arg (ap, void *) = done;			      \
+	{								      \
+	  if (is_longlong)						      \
+	    *(long long int *) va_arg (ap, void *) = done;		      \
+	  else if (is_long)						      \
+	    *(long int *) va_arg (ap, void *) = done;			      \
+	  else if (!is_short)						      \
+	    *(int *) va_arg (ap, void *) = done;			      \
+	  else								      \
+	    *(short int *) va_arg (ap, void *) = done;			      \
+	}								      \
       else								      \
 	if (is_longlong)						      \
 	  *(long long int *) args_value[fspec->data_arg].pa_pointer = done;   \
@@ -1360,8 +1376,8 @@ do_positional:
 	int showsign = specs[nspecs_done].info.showsign;
 	int group = specs[nspecs_done].info.group;
 	int is_long_double = specs[nspecs_done].info.is_long_double;
-	int is_short = specs[nspecs_done].info.is_short == 1;
-	int is_char = specs[nspecs_done].info.is_short == 2;
+	int is_short = specs[nspecs_done].info.is_short;
+	int is_char = specs[nspecs_done].info.is_char;
 	int is_long = specs[nspecs_done].info.is_long;
 	int width = specs[nspecs_done].info.width;
 	int prec = specs[nspecs_done].info.prec;
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 4bf3105269..aa7ac20c15 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98 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
@@ -720,8 +720,32 @@ extern int getsubopt __P ((char **__optionp, __const char *__const *__tokens,
 
 /* Setup DES tables according KEY.  */
 extern void setkey __P ((__const char *__key));
+
+/* X/Open pseudo terminal handling.  */
+
+/* The next four functions all take a master pseudo-tty fd and
+   perform an operation on the associated slave:  */
+
+/* Chown the slave to the calling user.  */
+extern int grantpt __P ((int __fd));
+
+/* Release an internal lock so the slave can be opened.
+   Call after grantpt().  */
+extern int unlockpt __P ((int __fd));
+
+/* Get the name of the slave.  */
+extern char *ptsname __P ((int __fd));
 #endif
 
+#ifdef __USE_GNU
+/* Reentrant version of ptsname.  */
+extern char *__ptsname_r __P ((int __fd, char *__buf, unsigned int __len));
+extern char *ptsname_r __P ((int __fd, char *__buf, unsigned int __len));
+
+/* Open a master pseudo tty and return its file descriptor.  */
+extern int __getpt __P ((void));
+extern int getpt __P ((void));
+#endif
 
 __END_DECLS
 
diff --git a/sysdeps/generic/getpt.c b/sysdeps/generic/getpt.c
new file mode 100644
index 0000000000..6dee1e12df
--- /dev/null
+++ b/sysdeps/generic/getpt.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <errno.h>
+
+/* Open the master side of a pseudoterminal and return its file
+   descriptor, or -1 on error. */
+int
+__getpt ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (getpt, __getpt)
+
+stub_warning (getpt)
+#include <stub-tag.h>
diff --git a/sysdeps/generic/grantpt.c b/sysdeps/generic/grantpt.c
new file mode 100644
index 0000000000..73c1821962
--- /dev/null
+++ b/sysdeps/generic/grantpt.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <errno.h>
+
+/* Given a fd on a master pseudoterminal, chown the file associated
+   with the slave to the calling process, and set its group and
+   mode appropriately.  Note that this is an unprivileged operation. */
+int
+grantpt (fd)
+     int fd __attribute__ ((unused));
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (grantpt)
+#include <stub-tag.h>
diff --git a/sysdeps/generic/inttypes.h b/sysdeps/generic/inttypes.h
index c5a74b8d2d..9ef0e8526a 100644
--- a/sysdeps/generic/inttypes.h
+++ b/sysdeps/generic/inttypes.h
@@ -1 +1 @@
-#error "This file must be written based on the data typs sizes of the target"
+#error "This file must be written based on the data type sizes of the target"
diff --git a/sysdeps/generic/ptsname.c b/sysdeps/generic/ptsname.c
new file mode 100644
index 0000000000..7a442d0d69
--- /dev/null
+++ b/sysdeps/generic/ptsname.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <errno.h>
+
+/* Given the file descriptor of a master pty, return the pathname
+   of the associated slave. */
+
+char *
+ptsname (fd)
+     int fd __attribute__ ((unused));
+{
+  __set_errno (ENOSYS);
+  return 0;
+}
+
+char *
+__ptsname_r (fd, buf, len)
+     int fd __attribute__ ((unused));
+     char *buf __attribute__ ((unused));
+     unsigned int len __attribute__ ((unused));
+{
+  __set_errno (ENOSYS);
+  return 0;
+}
+weak_alias (__ptsname_r, ptsname_r)
+
+stub_warning(ptsname)
+stub_warning(ptsname_r)
diff --git a/sysdeps/generic/pty.c b/sysdeps/generic/pty.c
deleted file mode 100644
index 75c7857f47..0000000000
--- a/sysdeps/generic/pty.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)pty.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <grp.h>
-#include <pty.h>
-#include <utmp.h>
-
-#ifndef REVOKE
-# define REVOKE(Line) revoke (Line)
-#endif
-
-int
-openpty(amaster, aslave, name, termp, winp)
-	int *amaster, *aslave;
-	char *name;
-	struct termios *termp;
-	struct winsize *winp;
-{
-	char line[11];
-	register const char *cp1, *cp2;
-	register int master, slave, ttygid;
-	size_t buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
-	char buffer[buflen];
-	struct group grbuffer;
-	struct group *gr;
-
-	strcpy (line, "/dev/ptyXX");
-
-	if (getgrnam_r("tty", &grbuffer, buffer, buflen, &gr) >= 0)
-		ttygid = gr->gr_gid;
-	else
-		ttygid = -1;
-
-	for (cp1 = "pqrs"; *cp1; cp1++) {
-		line[8] = *cp1;
-		for (cp2 = "0123456789abcdef"; *cp2; cp2++) {
-			line[9] = *cp2;
-			if ((master = open(line, O_RDWR, 0)) == -1) {
-				if (errno == ENOENT)
-					return (-1);	/* out of ptys */
-			} else {
-				line[5] = 't';
-				(void) chown(line, getuid(), ttygid);
-				(void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
-				REVOKE(line);
-				if ((slave = open(line, O_RDWR, 0)) != -1) {
-					*amaster = master;
-					*aslave = slave;
-					if (name)
-						strcpy(name, line);
-					if (termp)
-						(void) tcsetattr(slave,
-							TCSAFLUSH, termp);
-					if (winp)
-						(void) ioctl(slave, TIOCSWINSZ,
-							(char *)winp);
-					return (0);
-				}
-				(void) close(master);
-				line[5] = 'p';
-			}
-		}
-	}
-	__set_errno (ENOENT);	/* out of ptys */
-	return (-1);
-}
-
-int
-forkpty(amaster, name, termp, winp)
-	int *amaster;
-	char *name;
-	struct termios *termp;
-	struct winsize *winp;
-{
-	int master, slave, pid;
-
-	if (openpty(&master, &slave, name, termp, winp) == -1)
-		return (-1);
-	switch (pid = fork()) {
-	case -1:
-		return (-1);
-	case 0:
-		/*
-		 * child
-		 */
-		(void) close(master);
-		login_tty(slave);
-		return (0);
-	}
-	/*
-	 * parent
-	 */
-	*amaster = master;
-	(void) close(slave);
-	return (pid);
-}
diff --git a/sysdeps/generic/unlockpt.c b/sysdeps/generic/unlockpt.c
new file mode 100644
index 0000000000..5ee130971e
--- /dev/null
+++ b/sysdeps/generic/unlockpt.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <errno.h>
+
+/* Given a fd on a master pseudoterminal, clear a kernel lock so that
+   the slave can be opened.  This is to avoid a race between opening the
+   master and calling grantpt() to take possession of the slave. */
+int
+unlockpt (fd)
+     int fd __attribute__ ((unused));
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (unlockpt)
+#include <stub-tag.h>
diff --git a/sysdeps/unix/bsd/getpt.c b/sysdeps/unix/bsd/getpt.c
new file mode 100644
index 0000000000..cb47692fdd
--- /dev/null
+++ b/sysdeps/unix/bsd/getpt.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "pty-internal.h"
+
+/* Per the FreeBSD-3.0 manpages: pty masters are named
+   /dev/pty[p-sP-S][0-9a-v].  I hope EIO is the right
+   errno in the "already open" case; it doesn't say.  */
+static const char pn1[] = "pqrsPQRS";
+static const char pn2[] = "0123456789abcdefghijklmnopqrstuv";
+
+/* Open the master side of a pseudoterminal and return its file
+   descriptor, or -1 on error.  BSD version.  */
+int
+__getpt ()
+{
+  int fd;
+  const char *i, *j;
+  char namebuf[PTYNAMELEN];
+
+  strcpy (namebuf, "/dev/pty");
+  namebuf[10] = '\0';
+  for (i = pn1; *i; ++i)
+    {
+      namebuf[8] = *i;
+      for (j = pn2; *j; ++j)
+        {
+	  namebuf[9] = *j;
+	  fd = open (namebuf, O_RDWR);
+	  if (fd != -1)
+	    return fd;
+	  if (errno != EIO)
+	    return -1;
+        }
+    }
+  __set_errno (ENFILE);
+  return -1;
+}
+weak_alias (getpt, __getpt)
diff --git a/sysdeps/unix/bsd/unlockpt.c b/sysdeps/unix/bsd/unlockpt.c
new file mode 100644
index 0000000000..3de46eeda9
--- /dev/null
+++ b/sysdeps/unix/bsd/unlockpt.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <unistd.h>
+
+#include "pty-internal.h"
+
+/* Given a fd on a master pseudoterminal, clear a kernel lock so that
+   the slave can be opened.  This is to avoid a race between opening the
+   master and calling grantpt() to take possession of the slave.
+
+   BSD doesn't have this lock, but what it does have is revoke(). */
+
+int
+unlockpt (fd)
+     int fd;
+{
+  char buf[PTYNAMELEN];
+
+  if (ptsname_r (fd, buf, PTYNAMELEN))
+    return -1;
+
+  return revoke (buf);
+}
diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c
new file mode 100644
index 0000000000..4837a7a128
--- /dev/null
+++ b/sysdeps/unix/grantpt.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/resource.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <assert.h>
+
+#include "pty-internal.h"
+
+/* Given a fd on a master pseudoterminal, chown the file associated
+   with the slave to the calling process, and set its group and
+   mode appropriately.  Note that this is an unprivileged operation. */
+
+/* This "generic Unix" implementation works because we provide the program
+   /usr/libexec/pt_chown, and it only depends on ptsname() working. */
+static const char helper[] = LIBEXECDIR "/pt_chown";
+static const char *argv[] = { "pt_chown", NULL };
+
+int
+grantpt (fd)
+     int fd;
+{
+  struct stat st;
+  int w, pid;
+  char namebuf[PTYNAMELEN];
+
+  /* Some systems do it for us.  */
+  if (ptsname_r (fd, namebuf, PTYNAMELEN) == NULL)
+    return -1;
+  if (stat (namebuf, &st))
+    return -1;
+
+  if (st.st_uid == getuid ())
+    return 0;
+
+  /* We have to do it in user space.  */
+
+  pid = fork ();
+  if (pid == -1)
+    return -1;
+  else if (pid == 0)
+    {
+      /* Disable core dumps in the child.  */
+      struct rlimit off = { 0, 0 };
+      setrlimit (RLIMIT_CORE, &off);
+
+      /* The helper does its thing on fd PTY_FD.  */
+      if (fd != PTY_FD)
+	if (dup2 (fd, PTY_FD) == -1)
+	  _exit (FAIL_EBADF);
+
+      execve (helper, (char *const *) argv, 0);
+      _exit (FAIL_EXEC);
+    }
+  else
+    {
+      if (waitpid (pid, &w, 0) == -1)
+	return -1;
+      if (!WIFEXITED (w))
+	{
+	  __set_errno (ENOEXEC);
+	  return -1;
+	}
+      else
+	switch (WEXITSTATUS(w))
+	  {
+	  case 0:
+	    break;
+	  case FAIL_EBADF:
+	    __set_errno (EBADF);
+	    return -1;
+	  case FAIL_EINVAL:
+	    __set_errno (EINVAL);
+	    return -1;
+	  case FAIL_EACCES:
+	    __set_errno (EACCES);
+	    return -1;
+	  case FAIL_EXEC:
+	    __set_errno (ENOEXEC);
+	    return -1;
+
+	  default:
+	    assert(! "getpt: internal error: invalid exit code from pt_chown");
+	  }
+    }
+
+  /* Success.  */
+  return 0;
+}
diff --git a/sysdeps/unix/sysv/linux/Dist b/sysdeps/unix/sysv/linux/Dist
index 6743794281..c1b6ec91c2 100644
--- a/sysdeps/unix/sysv/linux/Dist
+++ b/sysdeps/unix/sysv/linux/Dist
@@ -33,6 +33,7 @@ netinet/tcp.h
 netinet/udp.h
 netipx/ipx.h
 netrom/netrom.h
+netrose/rose.h
 nfs/nfs.h
 rt_sigaction.c
 rt_sigpending.c
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 29f1566753..a71ee439a0 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -79,7 +79,8 @@ ifeq ($(subdir),inet)
 sysdep_headers += netinet/in_systm.h netinet/udp.h \
 		  netinet/if_fddi.h netinet/if_tr.h netinet/igmp.h \
 		  netinet/ip_fw.h  netinet/ip_icmp.h netipx/ipx.h \
-		  sys/socketvar.h netax25/ax25.h netrom/netrom.h
+		  sys/socketvar.h netax25/ax25.h netrom/netrom.h \
+		  netrose/rose.h
 endif
 
 ifeq ($(subdir),posix)
diff --git a/sysdeps/unix/sysv/linux/alpha/Dist b/sysdeps/unix/sysv/linux/alpha/Dist
index 715fda7bd3..5b5dca44da 100644
--- a/sysdeps/unix/sysv/linux/alpha/Dist
+++ b/sysdeps/unix/sysv/linux/alpha/Dist
@@ -9,6 +9,7 @@ ioperm.c
 kernel_sigaction.h
 kernel_stat.h
 kernel_termios.h
+net/route.h
 sys/acct.h
 sys/io.h
 sys/procfs.h
diff --git a/sysdeps/unix/sysv/linux/arm/Dist b/sysdeps/unix/sysv/linux/arm/Dist
index 738b9cc542..d987285445 100644
--- a/sysdeps/unix/sysv/linux/arm/Dist
+++ b/sysdeps/unix/sysv/linux/arm/Dist
@@ -1 +1,2 @@
+bits/mman.h
 clone.S
diff --git a/sysdeps/unix/sysv/linux/bits/ioctls.h b/sysdeps/unix/sysv/linux/bits/ioctls.h
index a89724cd71..7208d3bd4f 100644
--- a/sysdeps/unix/sysv/linux/bits/ioctls.h
+++ b/sysdeps/unix/sysv/linux/bits/ioctls.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 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
@@ -22,4 +22,87 @@
 
 /* Use the definitions from the kernel header files.  */
 #include <asm/ioctls.h>
-#include <linux/sockios.h>
+
+/* Routing table calls.  */
+#define SIOCADDRT	0x890B		/* add routing table entry	*/
+#define SIOCDELRT	0x890C		/* delete routing table entry	*/
+#define SIOCRTMSG	0x890D		/* call to routing system	*/
+
+/* Socket configuration controls. */
+#define SIOCGIFNAME	0x8910		/* get iface name		*/
+#define SIOCSIFLINK	0x8911		/* set iface channel		*/
+#define SIOCGIFCONF	0x8912		/* get iface list		*/
+#define SIOCGIFFLAGS	0x8913		/* get flags			*/
+#define SIOCSIFFLAGS	0x8914		/* set flags			*/
+#define SIOCGIFADDR	0x8915		/* get PA address		*/
+#define SIOCSIFADDR	0x8916		/* set PA address		*/
+#define SIOCGIFDSTADDR	0x8917		/* get remote PA address	*/
+#define SIOCSIFDSTADDR	0x8918		/* set remote PA address	*/
+#define SIOCGIFBRDADDR	0x8919		/* get broadcast PA address	*/
+#define SIOCSIFBRDADDR	0x891a		/* set broadcast PA address	*/
+#define SIOCGIFNETMASK	0x891b		/* get network PA mask		*/
+#define SIOCSIFNETMASK	0x891c		/* set network PA mask		*/
+#define SIOCGIFMETRIC	0x891d		/* get metric			*/
+#define SIOCSIFMETRIC	0x891e		/* set metric			*/
+#define SIOCGIFMEM	0x891f		/* get memory address (BSD)	*/
+#define SIOCSIFMEM	0x8920		/* set memory address (BSD)	*/
+#define SIOCGIFMTU	0x8921		/* get MTU size			*/
+#define SIOCSIFMTU	0x8922		/* set MTU size			*/
+#define	SIOCSIFHWADDR	0x8924		/* set hardware address 	*/
+#define SIOCGIFENCAP	0x8925		/* get/set encapsulations       */
+#define SIOCSIFENCAP	0x8926
+#define SIOCGIFHWADDR	0x8927		/* Get hardware address		*/
+#define SIOCGIFSLAVE	0x8929		/* Driver slaving support	*/
+#define SIOCSIFSLAVE	0x8930
+#define SIOCADDMULTI	0x8931		/* Multicast address lists	*/
+#define SIOCDELMULTI	0x8932
+#define SIOCGIFINDEX	0x8933		/* name -> if_index mapping	*/
+#define SIOGIFINDEX	SIOCGIFINDEX	/* misprint compatibility :-)	*/
+#define SIOCSIFPFLAGS	0x8934		/* set/get extended flags set	*/
+#define SIOCGIFPFLAGS	0x8935
+#define SIOCDIFADDR	0x8936		/* delete PA address		*/
+#define	SIOCSIFHWBROADCAST	0x8937	/* set hardware broadcast addr	*/
+#define SIOCGIFCOUNT	0x8938		/* get number of devices */
+
+#define SIOCGIFBR	0x8940		/* Bridging support		*/
+#define SIOCSIFBR	0x8941		/* Set bridging options 	*/
+
+#define SIOCGIFTXQLEN	0x8942		/* Get the tx queue length	*/
+#define SIOCSIFTXQLEN	0x8943		/* Set the tx queue length 	*/
+
+
+/* ARP cache control calls. */
+		    /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
+#define SIOCDARP	0x8953		/* delete ARP table entry	*/
+#define SIOCGARP	0x8954		/* get ARP table entry		*/
+#define SIOCSARP	0x8955		/* set ARP table entry		*/
+
+/* RARP cache control calls. */
+#define SIOCDRARP	0x8960		/* delete RARP table entry	*/
+#define SIOCGRARP	0x8961		/* get RARP table entry		*/
+#define SIOCSRARP	0x8962		/* set RARP table entry		*/
+
+/* Driver configuration calls */
+
+#define SIOCGIFMAP	0x8970		/* Get device parameters	*/
+#define SIOCSIFMAP	0x8971		/* Set device parameters	*/
+
+/* DLCI configuration calls */
+
+#define SIOCADDDLCI	0x8980		/* Create new DLCI device	*/
+#define SIOCDELDLCI	0x8981		/* Delete DLCI device		*/
+
+/* Device private ioctl calls.  */
+
+/* These 16 ioctls are available to devices via the do_ioctl() device
+   vector.  Each device should include this file and redefine these
+   names as their own. Because these are device dependent it is a good
+   idea _NOT_ to issue them to random objects and hope.  */
+
+#define SIOCDEVPRIVATE	0x89F0	/* to 89FF */
+
+/*
+ *	These 16 ioctl calls are protocol private
+ */
+
+#define SIOCPROTOPRIVATE 0x89E0 /* to 89EF */
diff --git a/sysdeps/unix/sysv/linux/bits/types.h b/sysdeps/unix/sysv/linux/bits/types.h
index 68cbf8ca7d..16111beed0 100644
--- a/sysdeps/unix/sysv/linux/bits/types.h
+++ b/sysdeps/unix/sysv/linux/bits/types.h
@@ -104,7 +104,7 @@ typedef struct
 typedef int __key_t;
 
 /* Used in `struct shmid_ds'.  */
-typedef short int __ipc_pid_t;
+typedef unsigned short int __ipc_pid_t;
 
 
 /* Types from the Large File Support interface.  */
diff --git a/sysdeps/unix/sysv/linux/getpt.c b/sysdeps/unix/sysv/linux/getpt.c
new file mode 100644
index 0000000000..8eea2ffa82
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getpt.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "pty-internal.h"
+
+/* Per Documentation/devices.txt: pty masters are /dev/pty[p-za-e][0-9a-f].
+   These strings are used also in ptsname.c. */
+const char __ptyname1[] = "pqrstuvwxyzabcde";
+const char __ptyname2[] = "0123456789abcdef";
+
+/* Open the master side of a pseudoterminal and return its file
+   descriptor, or -1 on error.  Linux version. */
+int
+__getpt ()
+{
+  int fd;
+  const char *i, *j;
+  static int have_dev_ptmx = 1;
+  char namebuf[PTYNAMELEN];
+
+  /* The new way:  */
+  if (have_dev_ptmx)
+    {
+      fd = open ("/dev/ptmx", O_RDWR);
+      if (fd != -1)
+	return fd;
+      else
+	{
+	  if (errno == ENOENT || errno == ENODEV)
+	    have_dev_ptmx = 0;
+	  else
+	    return -1;
+	}
+    }
+
+  /* The old way: */
+  strcpy (namebuf, "/dev/pty");
+  namebuf[10] = '\0';
+  for (i = __ptyname1; *i; ++i)
+    {
+      namebuf[8] = *i;
+      for (j = __ptyname2; *j; ++j)
+        {
+	  namebuf[9] = *j;
+	  fd = open (namebuf, O_RDWR);
+	  if (fd != -1)
+	    return fd;
+	  if (errno != EIO)
+	    return -1;
+        }
+    }
+  __set_errno (ENFILE);
+  return -1;
+}
+weak_alias (__getpt, getpt)
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index 2e0bc5bf8f..9d9bf0e0b2 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998 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
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <net/if.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index 1c9c095ed3..d026910ee2 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -16,7 +16,7 @@ sigsuspend	-	sigsuspend	1	__sigsuspend	sigsuspend
 # Socket functions; Linux/MIPS doesn't use the socketcall(2) wrapper;
 # it's provided for compatibility, though.
 #
-ccept		-	accept		3	__libc_accept	__accept accept
+accept		-	accept		3	__libc_accept	__accept accept
 bind		-	bind		3	__bind		bind
 connect		-	connect		3	__libc_connect	__connect connect
 getpeername	-	getpeername	3	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/m68k/sigreturn.S b/sysdeps/unix/sysv/linux/netrose/rose.h
index 34c0a91952..c158c66bb7 100644
--- a/sysdeps/unix/sysv/linux/m68k/sigreturn.S
+++ b/sysdeps/unix/sysv/linux/netrose/rose.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Definitions for Rose packet radio address family.
+   Copyright (C) 1998 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,14 +17,9 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <sysdep.h>
+#ifndef _NETROSE_ROSE_H
+#define _NETROSE_ROSE_H 1
 
-.text
-ENTRY (__sigreturn)
-	addq.l #4, %sp		/* Pop the return PC.  */
-	DO_CALL (#SYS_ify (sigreturn), 0)
-				/* Do the system call; it never returns.  */
-	/* NOTREACHED */
-END (__sigreturn)
+#include <linux/rose.h>		/* Ask, and the kernel will provide.  */
 
-weak_alias (__sigreturn, sigreturn)
+#endif
diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c
new file mode 100644
index 0000000000..04feadd436
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/ptsname.c
@@ -0,0 +1,108 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "pty-internal.h"
+
+#include <stdio-common/_itoa.h>
+#include <sys/sysmacros.h>
+
+/* Given the file descriptor of a master pty, return the pathname
+   of the associated slave. */
+
+static char namebuf[PTYNAMELEN];
+extern const char __ptyname1[], __ptyname2[]; /* defined in getpt.c */
+
+char *
+ptsname (fd)
+     int fd;
+{
+  return __ptsname_r (fd, namebuf, PTYNAMELEN);
+}
+
+char *
+__ptsname_r (fd, buf, len)
+     int fd;
+     char *buf;
+     unsigned int len;
+{
+  char nbuf[PTYNAMELEN], idbuf[6];
+  int ptyno;
+  struct stat st;
+
+#ifdef TIOCGPTN
+  static int tiocgptn_works = 1;
+  if (tiocgptn_works)
+    {
+      if (!ioctl (fd, TIOCGPTN, &ptyno))
+	goto gotit;
+      else
+	{
+	  if(errno != EINVAL)
+	    return 0;
+	  else
+	    tiocgptn_works = 0;
+	}
+    }
+#endif
+  /* /dev/ptmx will make it into the kernel before 32 bit dev_t, so
+     this should be safe.  */
+  if (fstat (fd, &st))
+    return 0;
+
+  ptyno = minor (st.st_rdev);
+
+#ifdef TIOCGPTN
+gotit:
+#endif
+  /* Two different possible naming schemes for pty slaves:
+     the SVr4 way.  */
+
+  idbuf[5] = '\0';
+  stpcpy (stpcpy (nbuf, "/dev/pts/"),
+	  _itoa_word (ptyno, &idbuf[4], 10, 0));
+  if (!stat (nbuf, &st))
+    {
+      strncpy (buf, nbuf, len);
+      return buf;
+    }
+  else
+    if (errno != ENOENT)
+      return NULL;
+
+  /* ...and the BSD way.  */
+  nbuf[7]  = 'y';
+  nbuf[8]  = __ptyname1[ptyno / 16];
+  nbuf[9]  = __ptyname2[ptyno % 16];
+  nbuf[10] = '\0';
+
+  if (stat (nbuf, &st))
+    return NULL;
+
+  strncpy (buf, nbuf, len);
+  return buf;
+}
+weak_alias (__ptsname_r, ptsname_r)
diff --git a/sysdeps/unix/sysv/linux/pty.c b/sysdeps/unix/sysv/linux/pty.c
deleted file mode 100644
index e64261c8c4..0000000000
--- a/sysdeps/unix/sysv/linux/pty.c
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Linux does not has the `revoke' function.  */
-#define REVOKE(Line)
-#include <sysdeps/generic/pty.c>
diff --git a/sysdeps/unix/sysv/linux/siglist.c b/sysdeps/unix/sysv/linux/siglist.c
index 43b229fc95..ae5ca6b8ec 100644
--- a/sysdeps/unix/sysv/linux/siglist.c
+++ b/sysdeps/unix/sysv/linux/siglist.c
@@ -1,3 +1,21 @@
+/* Copyright (C) 1997, 1998 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 <stddef.h>
 #include <signal.h>
 
diff --git a/sysdeps/unix/sysv/linux/unlockpt.c b/sysdeps/unix/sysv/linux/unlockpt.c
new file mode 100644
index 0000000000..e508b280c5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/unlockpt.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
+
+   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 <sys/ioctl.h>
+#include <termios.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* Given a fd on a master pseudoterminal, clear a kernel lock so that
+   the slave can be opened.  This is to avoid a race between opening the
+   master and calling grantpt() to take possession of the slave.  */
+int
+unlockpt (fd)
+     int fd __attribute__ ((unused));
+{
+#ifdef TIOCSPTLCK
+  int serrno = errno;
+  int unlock = 0;
+
+  if (ioctl (fd, TIOCSPTLCK, &unlock))
+    {
+      if(errno == EINVAL)
+	{
+	  __set_errno (serrno);
+	  return 0;
+	}
+      else
+	return -1;
+    }
+#else
+  /* On pre-/dev/ptmx kernels this function should be a no-op.  */
+  return 0;
+#endif
+}