about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog82
-rw-r--r--bits/types.h7
-rw-r--r--grp/grp.h8
-rw-r--r--include/features.h10
-rw-r--r--libio/fileops.c16
-rw-r--r--libio/ioseekoff.c14
-rw-r--r--libio/oldfileops.c16
-rw-r--r--libio/rewind.c1
-rw-r--r--locale/programs/charmap.c2
-rw-r--r--locale/programs/ld-ctype.c2
-rw-r--r--signal/signal.h12
-rw-r--r--string/bits/string2.h36
-rw-r--r--sysdeps/generic/bits/types.h7
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/fcntl.h12
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/time.h12
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/types.h11
-rw-r--r--sysdeps/unix/sysv/linux/bits/fcntl.h12
-rw-r--r--sysdeps/unix/sysv/linux/bits/time.h11
-rw-r--r--sysdeps/unix/sysv/linux/bits/types.h11
-rw-r--r--sysdeps/unix/sysv/linux/i386/bits/fcntl.h10
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/fcntl.h12
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/time.h9
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/types.h11
-rw-r--r--sysdeps/unix/sysv/linux/sparc/bits/fcntl.h12
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h11
-rw-r--r--sysdeps/unix/sysv/sysv4/solaris2/bits/types.h7
-rw-r--r--time/time.h2
27 files changed, 272 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index 5ebef7bc3f..bcf3cfef77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,85 @@
+1998-10-25  Ulrich Drepper  <drepper@cygnus.com>
+
+	* include/features.h: Define __USE_POSIS199506 is _POSIX_C_SOURCE is
+	greater or equal than 199506L.
+
+	* sysdeps/generic/bits/types.h (__fd_set): Define element as fds_bits
+	only is __USE_XOPEN.  Otherwise use __fds_bits.
+	* sysdeps/unix/sysv/linux/alpha/bits/types.h: Likewise.
+	* sysdeps/unix/sysv/linux/mips/bits/types.h: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h: Likewise.
+	* sysdeps/unix/sysv/linux/bits/types.h: Likewise.
+	* sysdeps/unix/sysv/sysv4/solaris2/bits/types.h: Likewise.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* locale/programs/charmap.c (parse_charmap): Accept tok_string
+	for <code_set_name>.
+
+1998-10-25  H.J. Lu  <hjl@gnu.org>
+
+	* locale/programs/ld-ctype.c (ctype_finish): Also check
+	<space>.
+
+1998-10-25  Ulrich Drepper  <drepper@cygnus.com>
+
+	* signal/signal.h: Include bits/sigthread.h only if __USE_POSIX199506.
+
+	* sysdeps/unix/sysv/linux/bits/types.h: Include pthreadtypes.h only
+	if __USE_POSIX199506 or __USE_UNIX98.
+
+1998-10-24 22:34 -0400  Zack Weinberg  <zack@rabi.phys.columbia.edu>
+
+	* string/bits/string2.h: Inline strdup+friends only if
+	__USE_MISC || __USE_GNU (prevents namespace pollution).
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* sysdeps/unix/sysv/linux/alpha/bits/fcntl.h (LOCK_SH,
+	LOCK_EX, LOCK_NB, LOCK_UN): Protect with __USE_BSD.
+	* sysdeps/unix/sysv/linux/i386/bits/fcntl.h (LOCK_SH, LOCK_EX,
+	LOCK_NB, LOCK_UN): Likewise.
+	* sysdeps/unix/sysv/linux/mips/bits/fcntl.h (LOCK_SH, LOCK_EX,
+	LOCK_NB, LOCK_UN): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/bits/fcntl.h (LOCK_SH, LOCK_EX,
+	LOCK_NB, LOCK_UN): Likewise.
+	* sysdeps/unix/sysv/linux/bits/fcntl.h (LOCK_SH, LOCK_EX,
+	LOCK_NB, LOCK_UN): Likewise.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* libio/ioseekoff.c (_IO_seekoff): Check the valid dir value.
+
+	* libio/rewind.c (rewind): Clear the error.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* grp/grp.h (getgrent_r, getgrgid_r, getgrnam_r): Add "__" to
+	"buffer".
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* sysdeps/unix/sysv/linux/alpha/bits/time.h (timeval): Protect
+	with __need_timeval.
+	* sysdeps/unix/sysv/linux/mips/bits/time.h (timeval): Likewise.
+	* sysdeps/unix/sysv/linux/bits/time.h (timeval): Likewise.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* signal/signal.h (timespec, siginfo_t, sigwaitinfo, sigtimedwait,
+	sigqueue): Protect with __USE_POSIX199309.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* time/time.h (timespec): Protect with __USE_POSIX199309 instead of
+	__USE_POSIX.
+
+1998-10-24  H.J. Lu  <hjl@gnu.org>
+
+	* libio/fileops.c (_IO_new_file_seekoff): Always resync with
+	the kernel file offset.
+	* libio/oldfileops.c (_IO_old_file_seekoff): Likewise.
+
 1998-10-24  H.J. Lu  <hjl@gnu.org>
 
 	* time/tzfile.c (__tzfile_default): Set num_types to 2.
diff --git a/bits/types.h b/bits/types.h
index d79851c22a..2b3edab5e4 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -98,8 +98,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#else
+    __fd_mask __fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#endif
   } __fd_set;
 
 
diff --git a/grp/grp.h b/grp/grp.h
index 1059df089f..9b71df8eb7 100644
--- a/grp/grp.h
+++ b/grp/grp.h
@@ -99,25 +99,25 @@ extern struct group *getgrnam __P ((__const char *__name));
    POSIX people would choose.  */
 
 # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
-extern int getgrent_r __P ((struct group *__resultbuf, char *buffer,
+extern int getgrent_r __P ((struct group *__resultbuf, char *__buffer,
 			    size_t __buflen, struct group **__result));
 # endif
 
 /* Search for an entry with a matching group ID.  */
 extern int getgrgid_r __P ((__gid_t __gid, struct group *__resultbuf,
-			    char *buffer, size_t __buflen,
+			    char *__buffer, size_t __buflen,
 			    struct group **__result));
 
 /* Search for an entry with a matching group name.  */
 extern int getgrnam_r __P ((__const char *__name, struct group *__resultbuf,
-			    char *buffer, size_t __buflen,
+			    char *__buffer, size_t __buflen,
 			    struct group **__result));
 
 # ifdef	__USE_SVID
 /* Read a group entry from STREAM.  This function is not standardized
    an probably never will.  */
 extern int fgetgrent_r __P ((FILE * __stream, struct group *__resultbuf,
-			     char *buffer, size_t __buflen,
+			     char *__buffer, size_t __buflen,
 			     struct group **__result));
 # endif
 
diff --git a/include/features.h b/include/features.h
index 8cfc990f69..c0edd106ee 100644
--- a/include/features.h
+++ b/include/features.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
@@ -51,7 +51,8 @@
    __USE_ISOC9X		Define ISO C 9X things.
    __USE_POSIX		Define IEEE Std 1003.1 things.
    __USE_POSIX2		Define IEEE Std 1003.2 things.
-   __USE_POSIX199309	Define IEEE Std 1003.1b things.
+   __USE_POSIX199309	Define IEEE Std 1003.1, and .1b things.
+   __USE_POSIX199506	Define IEEE Std 1003.1, .1b, .1c and .1i things.
    __USE_XOPEN		Define XPG things.
    __USE_XOPEN_EXTENDED	Define X/Open Unix things.
    __USE_UNIX98		Define Single Unix V2 things.
@@ -81,6 +82,7 @@
 #undef	__USE_POSIX
 #undef	__USE_POSIX2
 #undef	__USE_POSIX199309
+#undef	__USE_POSIX199506
 #undef	__USE_XOPEN
 #undef	__USE_XOPEN_EXTENDED
 #undef	__USE_UNIX98
@@ -173,6 +175,10 @@
 # define __USE_POSIX199309	1
 #endif
 
+#if (_POSIX_C_SOURCE - 0) >= 199506L
+# define __USE_POSIX199506	1
+#endif
+
 #ifdef	_XOPEN_SOURCE
 # define __USE_XOPEN	1
 # if (_XOPEN_SOURCE - 0) == 500
diff --git a/libio/fileops.c b/libio/fileops.c
index be65d42fb2..8930f6f3cd 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -567,7 +567,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
 	      _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
 	      {
 		_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
-		return offset;
+		goto resync;
 	      }
 	    }
 #ifdef TODO
@@ -579,7 +579,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
 		if (ignore (to_skip) != to_skip)
 		  goto dumb;
 		_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
-		return offset;
+		goto resync;
 	      }
 #endif
 	}
@@ -590,7 +590,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
 	    _IO_switch_to_backup_area (fp);
 	  gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
 	  _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
-	  return offset;
+	  goto resync;
 	}
 #endif
     }
@@ -646,6 +646,16 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
       _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
     }
   return result;
+
+resync:
+  /* We need to do it since it is possible that the file offset in
+     the kernel may be changed behind our back. It may happen when
+     we fopen a file and then do a fork. One process may access the
+     the file and the kernel file offset will be changed. */
+  if (fp->_offset >= 0)
+    _IO_SYSSEEK (fp, fp->_offset, 0);
+
+  return offset;
 }
 
 _IO_ssize_t
diff --git a/libio/ioseekoff.c b/libio/ioseekoff.c
index 54a8d19f0d..4a951dd7c1 100644
--- a/libio/ioseekoff.c
+++ b/libio/ioseekoff.c
@@ -24,6 +24,13 @@
    General Public License.  */
 
 #include <libioP.h>
+#include <errno.h> 
+#ifndef errno 
+extern int errno; 
+#endif 
+#ifndef __set_errno 
+# define __set_errno(Val) errno = (Val)  
+#endif 
 
 _IO_fpos64_t
 _IO_seekoff (fp, offset, dir, mode)
@@ -34,13 +41,18 @@ _IO_seekoff (fp, offset, dir, mode)
 {
   _IO_fpos64_t retval;
 
+  if (dir != _IO_seek_cur && dir != _IO_seek_set && dir != _IO_seek_end) 
+    { 
+      __set_errno (EINVAL); 
+      return EOF; 
+    }
+
   /* If we have a backup buffer, get rid of it, since the __seekoff
      callback may not know to do the right thing about it.
      This may be over-kill, but it'll do for now. TODO */
   _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
   _IO_flockfile (fp);
 
-
   if (mode != 0 && _IO_have_backup (fp))
     {
       if (dir == _IO_seek_cur && _IO_in_backup (fp))
diff --git a/libio/oldfileops.c b/libio/oldfileops.c
index 59de8d8818..e0f8e65255 100644
--- a/libio/oldfileops.c
+++ b/libio/oldfileops.c
@@ -514,7 +514,7 @@ _IO_old_file_seekoff (fp, offset, dir, mode)
 	      _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
 			fp->_IO_read_end);
 	      _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
-	      return offset;
+	      goto resync;
 	    }
 #ifdef TODO
 	    /* If we have streammarkers, seek forward by reading ahead. */
@@ -524,7 +524,7 @@ _IO_old_file_seekoff (fp, offset, dir, mode)
 		  - (fp->_IO_read_ptr - fp->_IO_read_base);
 		if (ignore (to_skip) != to_skip)
 		  goto dumb;
-		return offset;
+		goto resync;
 	      }
 #endif
 	}
@@ -534,7 +534,7 @@ _IO_old_file_seekoff (fp, offset, dir, mode)
 	  if (!_IO_in_backup (fp))
 	    _IO_switch_to_backup_area (fp);
 	  gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
-	  return offset;
+	  goto resync;
 	}
 #endif
     }
@@ -590,6 +590,16 @@ _IO_old_file_seekoff (fp, offset, dir, mode)
       _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
     }
   return result;
+
+resync:
+  /* We need to do it since it is possible that the file offset in
+     the kernel may be changed behind our back. It may happen when
+     we fopen a file and then do a fork. One process may access the
+     the file and the kernel file offset will be changed. */
+  if (fp->_old_offset >= 0)
+    _IO_SYSSEEK (fp, fp->_old_offset, 0);
+
+  return offset;
 }
 
 _IO_ssize_t
diff --git a/libio/rewind.c b/libio/rewind.c
index fb6afbc77a..a9ea36edb6 100644
--- a/libio/rewind.c
+++ b/libio/rewind.c
@@ -34,6 +34,7 @@ rewind (fp)
   _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
   _IO_flockfile (fp);
   _IO_rewind (fp);
+  _IO_clearerr (fp);
   _IO_funlockfile (fp);
   _IO_cleanup_region_end (0);
 }
diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c
index e11df1cf29..fd9cc357e3 100644
--- a/locale/programs/charmap.c
+++ b/locale/programs/charmap.c
@@ -290,7 +290,7 @@ parse_charmap (const char *filename)
 	  switch (nowtok)
 	    {
 	    case tok_code_set_name:
-	      if (arg->tok != tok_ident)
+	      if (arg->tok != tok_ident && arg->tok != tok_string)
 		{
 		badarg:
 		  lr_error (cmfile, _("syntax error in prolog: %s"),
diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
index a4dcd76807..2fbefd9395 100644
--- a/locale/programs/ld-ctype.c
+++ b/locale/programs/ld-ctype.c
@@ -313,6 +313,8 @@ character %s'%s' in class `%s' must not be in class `%s'"),
   /* ... and now test <SP> as a special case.  */
   space_value = charset_find_value (&charset->char_table, "SP", 2);
   if ((wchar_t) space_value == ILLEGAL_CHAR_VALUE)
+    space_value = charset_find_value (&charset->char_table, "space", 5);
+  if ((wchar_t) space_value == ILLEGAL_CHAR_VALUE)
     {
       if (!be_quiet)
 	error (0, 0, _("character <SP> not defined in character map"));
diff --git a/signal/signal.h b/signal/signal.h
index 62ccf19699..efbe36d378 100644
--- a/signal/signal.h
+++ b/signal/signal.h
@@ -179,12 +179,14 @@ typedef __sighandler_t sig_t;
 
 #ifdef __USE_POSIX
 
+# ifdef __USE_POSIX199309
 /* We need `struct timespec' later on.  */
 #  define __need_timespec
 #  include <time.h>
 
 /* Get the `siginfo_t' type plus the needed symbols.  */
 #  include <bits/siginfo.h>
+# endif
 
 /* Clear all signals from SET.  */
 extern int sigemptyset __P ((sigset_t *__set));
@@ -201,7 +203,7 @@ extern int sigdelset __P ((sigset_t *__set, int __signo));
 /* Return 1 if SIGNO is in SET, 0 if not.  */
 extern int sigismember __P ((__const sigset_t *__set, int __signo));
 
-#  ifdef __USE_GNU
+# ifdef __USE_GNU
 /* Return non-empty value is SET is not empty.  */
 extern int sigisemptyset __P ((__const sigset_t *__set));
 
@@ -212,11 +214,11 @@ extern int sigandset __P ((sigset_t *__set, __const sigset_t *__left,
 /* Build new signal set by combining the two inputs set using logical OR.  */
 extern int sigorset __P ((sigset_t *__set, __const sigset_t *__left,
 			  __const sigset_t *__right));
-#  endif /* GNU */
+# endif /* GNU */
 
 /* Get the system-specific definitions of `struct sigaction'
    and the `SA_*' and `SIG_*'. constants.  */
-#  include <bits/sigaction.h>
+# include <bits/sigaction.h>
 
 /* Get and/or change the set of blocked signals.  */
 extern int sigprocmask __P ((int __how,
@@ -239,6 +241,7 @@ extern int sigpending __P ((sigset_t *__set));
 /* Select any of pending signals from SET or wait for any to arrive.  */
 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
 
+# ifdef __USE_POSIX199309
 /* Select any of pending signals from SET and place information in INFO.  */
 extern int sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
 
@@ -251,6 +254,7 @@ extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
    signal.  */
 extern int sigqueue __P ((__pid_t __pid, int __sig,
 			  __const union sigval __val));
+# endif	/* Use POSIX 199306.  */
 
 #endif /* Use POSIX.  */
 
@@ -333,7 +337,7 @@ extern int sigignore __P ((int __sig));
 extern __sighandler_t sigset __P ((int __sig, __sighandler_t __disp));
 #endif /* use Unix98 */
 
-#ifdef __USE_POSIX
+#ifdef __USE_POSIX199506
 /* Some of the functions for handling signals in threaded programs must
    be defined here.  */
 # include <bits/sigthread.h>
diff --git a/string/bits/string2.h b/string/bits/string2.h
index fd431b8ece..cfbcc18aa0 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -1011,18 +1011,18 @@ __strsep_g (char **__s, __const char *__reject)
 #endif
 
 /* We need the memory allocation functions for inline strdup().
-   Referring to stdlib.h (even minimally) is not allowed if
-   __STRICT_ANSI__. */
-#ifndef __STRICT_ANSI__
+   Referring to stdlib.h (even minimally) is not allowed 
+   in any of the tight standards compliant modes.  */
+#if defined __USE_MISC || defined __USE_GNU
 
-#if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
-# define __need_malloc_and_calloc
-# include <stdlib.h>
-#endif
+# if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
+#  define __need_malloc_and_calloc
+#  include <stdlib.h>
+# endif
 
-#ifndef _HAVE_STRING_ARCH_strdup
+# ifndef _HAVE_STRING_ARCH_strdup
 
-# define __strdup(s) \
+#  define __strdup(s) \
   (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)	      \
 		  ? (((__const char *) (s))[0] == '\0'			      \
 		     ? (char *) calloc (1, 1)				      \
@@ -1033,14 +1033,14 @@ __strsep_g (char **__s, __const char *__reject)
 			  __retval; }))					      \
 		  : __strdup (s)))
 
-# if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
-#  define strdup(s) __strdup (s)
+#  if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
+#   define strdup(s) __strdup (s)
+#  endif
 # endif
-#endif
 
-#ifndef _HAVE_STRING_ARCH_strndup
+# ifndef _HAVE_STRING_ARCH_strndup
 
-# define __strndup(s, n) \
+#  define __strndup(s, n) \
   (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)	      \
 		  ? (((__const char *) (s))[0] == '\0'			      \
 		     ? (char *) calloc (1, 1)				      \
@@ -1059,12 +1059,12 @@ __strsep_g (char **__s, __const char *__reject)
 			  __retval; }))					      \
 		  : __strndup ((s), (n))))
 
-# ifdef __GNU_SOURCE
-#  define strndup(s, n) __strndup ((s), (n))
+#  ifdef __GNU_SOURCE
+#   define strndup(s, n) __strndup ((s), (n))
+#  endif
 # endif
-#endif
 
-#endif /* Strict ANSI */
+#endif /* Use misc. or use GNU.  */
 
 #undef __STRING_INLINE
 
diff --git a/sysdeps/generic/bits/types.h b/sysdeps/generic/bits/types.h
index d79851c22a..2b3edab5e4 100644
--- a/sysdeps/generic/bits/types.h
+++ b/sysdeps/generic/bits/types.h
@@ -98,8 +98,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#else
+    __fd_mask __fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#endif
   } __fd_set;
 
 
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h b/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
index 70ebbeba61..9f90ddf57c 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/fcntl.h
@@ -89,12 +89,14 @@
 #define F_EXLCK		16	/* or 3 */
 #define F_SHLCK		32	/* or 4 */
 
-/* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH		1	/* shared lock */
-#define LOCK_EX		2	/* exclusive lock */
-#define LOCK_NB		4	/* or'd with one of the above to prevent
+/* Operations for bsd flock(), also used by the kernel implementation */
+#ifdef __USE_BSD
+# define LOCK_SH	1	/* shared lock */
+# define LOCK_EX	2	/* exclusive lock */
+# define LOCK_NB	4	/* or'd with one of the above to prevent
 				   blocking */
-#define LOCK_UN		8	/* remove lock */
+# define LOCK_UN	8	/* remove lock */
+#endif
 
 /* We don't need to support __USE_FILE_OFFSET64.  */
 struct flock
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/time.h b/sysdeps/unix/sysv/linux/alpha/bits/time.h
index acb2b41f97..f44b5dcabc 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/time.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/time.h
@@ -42,10 +42,11 @@
 # endif	/* bits/time.h */
 #endif /* !__need_timeval */
 
-
-#ifndef _STRUCT_TIMEVAL
-# define _STRUCT_TIMEVAL	1
-# include <bits/types.h>
+#ifdef __need_timeval 
+# undef __need_timeval
+# ifndef _STRUCT_TIMEVAL
+#  define _STRUCT_TIMEVAL	1
+#  include <bits/types.h>
 
 /* A time value that is accurate to the nearest
    microsecond but also has a range of years.  */
@@ -54,4 +55,5 @@ struct timeval
     __time_t tv_sec;		/* Seconds.  */
     __time_t tv_usec;		/* Microseconds.  */
   };
-#endif	/* struct timeval */
+# endif	/* struct timeval */
+#endif	/* need timeval */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/types.h b/sysdeps/unix/sysv/linux/alpha/bits/types.h
index d4f2217f05..aee9d046ec 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/types.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/types.h
@@ -102,8 +102,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
+#else
+    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
+#endif
   } __fd_set;
 
 /* Used in XTI.  */
@@ -115,6 +120,8 @@ typedef long int __intptr_t;
 
 
 /* Now add the thread types.  */
-#include <bits/pthreadtypes.h>
+#if defined __USE_POSIX199506 || defined __USE_UNIX98
+# include <bits/pthreadtypes.h>
+#endif
 
 #endif /* bits/types.h */
diff --git a/sysdeps/unix/sysv/linux/bits/fcntl.h b/sysdeps/unix/sysv/linux/bits/fcntl.h
index a2bbf29e03..0c94c6b9a5 100644
--- a/sysdeps/unix/sysv/linux/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/bits/fcntl.h
@@ -96,12 +96,14 @@
 #define F_EXLCK		4	/* or 3 */
 #define F_SHLCK		8	/* or 4 */
 
-/* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH		1	/* shared lock */
-#define LOCK_EX		2	/* exclusive lock */
-#define LOCK_NB		4	/* or'd with one of the above to prevent
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH	1	/* shared lock */
+# define LOCK_EX	2	/* exclusive lock */
+# define LOCK_NB	4	/* or'd with one of the above to prevent
 				   blocking */
-#define LOCK_UN		8	/* remove lock */
+# define LOCK_UN	8	/* remove lock */
+#endif
 
 struct flock
   {
diff --git a/sysdeps/unix/sysv/linux/bits/time.h b/sysdeps/unix/sysv/linux/bits/time.h
index 3c1b27a1bb..274d616777 100644
--- a/sysdeps/unix/sysv/linux/bits/time.h
+++ b/sysdeps/unix/sysv/linux/bits/time.h
@@ -42,9 +42,11 @@
 # endif	/* bits/time.h */
 #endif
 
-#ifndef _STRUCT_TIMEVAL
-# define _STRUCT_TIMEVAL	1
-# include <bits/types.h>
+#ifdef __need_timeval 
+# undef __need_timeval
+# ifndef _STRUCT_TIMEVAL
+#  define _STRUCT_TIMEVAL	1
+#  include <bits/types.h>
 
 /* A time value that is accurate to the nearest
    microsecond but also has a range of years.  */
@@ -53,4 +55,5 @@ struct timeval
     __time_t tv_sec;		/* Seconds.  */
     __time_t tv_usec;		/* Microseconds.  */
   };
-#endif	/* struct timeval */
+# endif	/* struct timeval */
+#endif	/* need timeval */ 
diff --git a/sysdeps/unix/sysv/linux/bits/types.h b/sysdeps/unix/sysv/linux/bits/types.h
index 06206f3b55..1543ff7c34 100644
--- a/sysdeps/unix/sysv/linux/bits/types.h
+++ b/sysdeps/unix/sysv/linux/bits/types.h
@@ -99,8 +99,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the global namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
+#else
+    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
+#endif
   } __fd_set;
 
 
@@ -139,6 +144,8 @@ typedef int __intptr_t;
 
 
 /* Now add the thread types.  */
-#include <bits/pthreadtypes.h>
+#if defined __USE_POSIX199506 || defined __USE_UNIX98
+# include <bits/pthreadtypes.h>
+#endif
 
 #endif /* bits/types.h */
diff --git a/sysdeps/unix/sysv/linux/i386/bits/fcntl.h b/sysdeps/unix/sysv/linux/i386/bits/fcntl.h
index d4ef8e1096..d47a661917 100644
--- a/sysdeps/unix/sysv/linux/i386/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/i386/bits/fcntl.h
@@ -96,12 +96,14 @@
 #define F_EXLCK		4	/* or 3 */
 #define F_SHLCK		8	/* or 4 */
 
+#ifdef __USE_BSD
 /* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH		1	/* shared lock */
-#define LOCK_EX		2	/* exclusive lock */
-#define LOCK_NB		4	/* or'd with one of the above to prevent
+# define LOCK_SH	1	/* shared lock */
+# define LOCK_EX	2	/* exclusive lock */
+# define LOCK_NB	4	/* or'd with one of the above to prevent
 				   blocking */
-#define LOCK_UN		8	/* remove lock */
+# define LOCK_UN	8	/* remove lock */
+#endif
 
 struct flock
   {
diff --git a/sysdeps/unix/sysv/linux/mips/bits/fcntl.h b/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
index 027347053b..0a21a59e0a 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/fcntl.h
@@ -86,12 +86,14 @@
 #define F_EXLCK		4	/* or 3 */
 #define F_SHLCK		8	/* or 4 */
 
-/* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH		1	/* shared lock */
-#define LOCK_EX		2	/* exclusive lock */
-#define LOCK_NB		4	/* or'd with one of the above to prevent		XXXXXXXXXXXXXXXXXX
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH	1	/* shared lock */
+# define LOCK_EX	2	/* exclusive lock */
+# define LOCK_NB	4	/* or'd with one of the above to prevent		XXXXXXXXXXXXXXXXXX
 				   blocking */
-#define LOCK_UN		8	/* remove lock */
+# define LOCK_UN	8	/* remove lock */
+#endif
 
 typedef struct flock
   {
diff --git a/sysdeps/unix/sysv/linux/mips/bits/time.h b/sysdeps/unix/sysv/linux/mips/bits/time.h
index 91dc65c910..15c7cb3852 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/time.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/time.h
@@ -42,8 +42,10 @@
 # endif  /* bits/time.h */
 #endif
 
-#ifndef _STRUCT_TIMEVAL
-# define _STRUCT_TIMEVAL	1
+#ifdef __need_timeval 
+# undef __need_timeval
+# ifndef _STRUCT_TIMEVAL
+#  define _STRUCT_TIMEVAL	1
 /* A time value that is accurate to the nearest
    microsecond but also has a range of years.  */
 struct timeval
@@ -51,4 +53,5 @@ struct timeval
     long int tv_sec;		/* Seconds.  */
     long int tv_usec;		/* Microseconds.  */
   };
-#endif	/* struct timeval */
+# endif	/* struct timeval */
+#endif	/* need timeval */
diff --git a/sysdeps/unix/sysv/linux/mips/bits/types.h b/sysdeps/unix/sysv/linux/mips/bits/types.h
index c716d5735d..e32dadf57f 100644
--- a/sysdeps/unix/sysv/linux/mips/bits/types.h
+++ b/sysdeps/unix/sysv/linux/mips/bits/types.h
@@ -99,8 +99,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
+#else
+    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
+#endif
   } __fd_set;
 
 
@@ -139,6 +144,8 @@ typedef int __intptr_t;
 
 
 /* Now add the thread types.  */
-#include <bits/pthreadtypes.h>
+#if defined __USE_POSIX199506 || defined __USE_UNIX98
+# include <bits/pthreadtypes.h>
+#endif
 
 #endif /* bits/types.h */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h b/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
index b86c65d993..e42dfefef6 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/fcntl.h
@@ -79,12 +79,14 @@
 #define F_EXLCK		4	/* or 3 */
 #define F_SHLCK		8	/* or 4 */
 
-/* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH		1	/* shared lock */
-#define LOCK_EX		2	/* exclusive lock */
-#define LOCK_NB		4	/* or'd with one of the above to prevent
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation */
+# define LOCK_SH	1	/* shared lock */
+# define LOCK_EX	2	/* exclusive lock */
+# define LOCK_NB	4	/* or'd with one of the above to prevent
 				   blocking */
-#define LOCK_UN		8	/* remove lock */
+# define LOCK_UN	8	/* remove lock */
+#endif
 
 struct flock
   {
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h b/sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h
index c147dbe6e5..6093eba084 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h
@@ -93,8 +93,13 @@ typedef unsigned long int __fd_mask;
 /* fd_set for select and pselect.  */
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
+#else
+    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
+#endif
   } __fd_set;
 
 
@@ -127,6 +132,8 @@ typedef long int __intptr_t;
 
 
 /* Now add the thread types.  */
-#include <bits/pthreadtypes.h>
+#if defined __USE_POSIX199506 || defined __USE_UNIX98
+# include <bits/pthreadtypes.h>
+#endif
 
 #endif /* bits/types.h */
diff --git a/sysdeps/unix/sysv/sysv4/solaris2/bits/types.h b/sysdeps/unix/sysv/sysv4/solaris2/bits/types.h
index e25dec98fb..aa73ebcb19 100644
--- a/sysdeps/unix/sysv/sysv4/solaris2/bits/types.h
+++ b/sysdeps/unix/sysv/sysv4/solaris2/bits/types.h
@@ -90,8 +90,13 @@ typedef int __key_t;		     /* Type of an IPC key */
 
 typedef struct
   {
-    /* XPG4.2 requires this member name.  */
+    /* XPG4.2 requires this member name.  Otherwise avoid the name
+       from the user namespace.  */
+#ifdef __USE_XOPEN
     unsigned long int fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#else
+    unsigned long int __fds_bits[(__FD_SETSIZE + (__NFDBITS - 1)) / __NFDBITS];
+#endif
   } __fd_set;
 
 typedef unsigned long int __fd_mask;
diff --git a/time/time.h b/time/time.h
index 0af3eafddb..374885290a 100644
--- a/time/time.h
+++ b/time/time.h
@@ -80,7 +80,7 @@ typedef __time_t time_t;
 
 
 #if !defined __timespec_defined && \
-    ((defined _TIME_H && defined __USE_POSIX) || defined __need_timespec)
+    ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timespec)
 # define __timespec_defined	1
 
 /* POSIX.4 structure for a time value.  This is like a `struct timeval' but