diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-08-20 19:50:45 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-08-20 19:50:45 +0200 |
commit | 4dd9e35bfd35d3138bc44169baba098005bad51e (patch) | |
tree | a4939c43a9c3fe00eb27f023e14acc5e1fe8808c /sysdeps/posix | |
parent | bd42a4599d1b6f77bcfe1e4f67b7cbd9e1cb2dfd (diff) | |
parent | f76453c31593957fec1a99b986bfa5506618b79c (diff) |
Merge commit 'refs/top-bases/t/bigmem' into t/bigmem
Diffstat (limited to 'sysdeps/posix')
87 files changed, 656 insertions, 612 deletions
diff --git a/sysdeps/posix/Makefile b/sysdeps/posix/Makefile index b58aa6aadb..52f20f5d97 100644 --- a/sysdeps/posix/Makefile +++ b/sysdeps/posix/Makefile @@ -3,3 +3,9 @@ L_tmpnam = 20 TMP_MAX = 238328 L_ctermid = 9 L_cuserid = 9 + +ifeq ($(subdir)|$(have-thread-library),rt|no) +# With NPTL, this lives in libpthread so it can be used for sem_open too. +# Without NPTL, it's just private in librt. +librt-routines += shm-directory +endif diff --git a/sysdeps/posix/Subdirs b/sysdeps/posix/Subdirs new file mode 100644 index 0000000000..a46884d4f8 --- /dev/null +++ b/sysdeps/posix/Subdirs @@ -0,0 +1 @@ +login diff --git a/sysdeps/posix/alarm.c b/sysdeps/posix/alarm.c index c68ae51d4a..002366462c 100644 --- a/sysdeps/posix/alarm.c +++ b/sysdeps/posix/alarm.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/clock.c b/sysdeps/posix/clock.c index d91b56a705..d425190bdc 100644 --- a/sysdeps/posix/clock.c +++ b/sysdeps/posix/clock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c index 27f264bb16..7202b9b07d 100644 --- a/sysdeps/posix/clock_getres.c +++ b/sysdeps/posix/clock_getres.c @@ -1,5 +1,5 @@ /* clock_getres -- Get the resolution of a POSIX clockid_t. - Copyright (C) 1999-2014 Free Software Foundation, Inc. + Copyright (C) 1999-2015 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 @@ -30,7 +30,7 @@ static long int nsec; /* Clock frequency of the processor. */ static int hp_timing_getres (struct timespec *res) { - if (__builtin_expect (nsec == 0, 0)) + if (__glibc_unlikely (nsec == 0)) { hp_timing_t freq; @@ -39,7 +39,7 @@ hp_timing_getres (struct timespec *res) code against multiple execution since all of them should lead to the same result. */ freq = __get_clockfreq (); - if (__builtin_expect (freq == 0, 0)) + if (__glibc_unlikely (freq == 0)) /* Something went wrong. */ return -1; @@ -60,7 +60,7 @@ realtime_getres (struct timespec *res) { long int clk_tck = sysconf (_SC_CLK_TCK); - if (__builtin_expect (clk_tck != -1, 1)) + if (__glibc_likely (clk_tck != -1)) { /* This implementation assumes that the realtime clock has a resolution higher than 1 second. This is the case for any diff --git a/sysdeps/posix/closedir.c b/sysdeps/posix/closedir.c index 24ba1a5c42..e352c0b1af 100644 --- a/sysdeps/posix/closedir.c +++ b/sysdeps/posix/closedir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -43,7 +43,7 @@ __closedir (DIR *dirp) fd = dirp->fd; -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_fini (dirp->lock); #endif diff --git a/sysdeps/posix/ctermid.c b/sysdeps/posix/ctermid.c index 0ef9a3fe23..5a6ff02d78 100644 --- a/sysdeps/posix/ctermid.c +++ b/sysdeps/posix/ctermid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -19,17 +19,17 @@ #include <string.h> -/* Return the name of the controlling terminal. - If S is not NULL, the name is copied into it (it should be at - least L_ctermid bytes long), otherwise a static buffer is used. */ +/* Return the name of the controlling terminal. If S is not NULL, the + name is copied into it (it should be at least L_ctermid bytes + long), otherwise we return a pointer to a non-const but read-only + string literal, that POSIX states the caller must not modify. */ char * -ctermid (s) - char *s; +ctermid (char *s) { - static char name[L_ctermid]; + char *name = (char /*drop const*/ *) "/dev/tty"; if (s == NULL) - s = name; + return name; - return strcpy (s, "/dev/tty"); + return strcpy (s, name); } diff --git a/sysdeps/posix/cuserid.c b/sysdeps/posix/cuserid.c index 57ddca4ef3..acdd20cd5e 100644 --- a/sysdeps/posix/cuserid.c +++ b/sysdeps/posix/cuserid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/dirfd.c b/sysdeps/posix/dirfd.c index 5af57146fd..1630f8987b 100644 --- a/sysdeps/posix/dirfd.c +++ b/sysdeps/posix/dirfd.c @@ -1,5 +1,5 @@ /* Return the file descriptor used by a DIR stream. Unix version. - Copyright (C) 1995-2014 Free Software Foundation, Inc. + Copyright (C) 1995-2015 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 diff --git a/sysdeps/posix/dirstream.h b/sysdeps/posix/dirstream.h index dadc30e8dd..c7e1a5af5c 100644 --- a/sysdeps/posix/dirstream.h +++ b/sysdeps/posix/dirstream.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2014 Free Software Foundation, Inc. +/* Copyright (C) 1993-2015 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 diff --git a/sysdeps/posix/dl-fileid.h b/sysdeps/posix/dl-fileid.h new file mode 100644 index 0000000000..d0d5436641 --- /dev/null +++ b/sysdeps/posix/dl-fileid.h @@ -0,0 +1,50 @@ +/* File identity for the dynamic linker. Generic POSIX.1 version. + Copyright (C) 2015 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdbool.h> +#include <sys/stat.h> + +/* For POSIX.1 systems, the pair of st_dev and st_ino constitute + a unique identifier for a file. */ +struct r_file_id + { + dev_t dev; + ino64_t ino; + }; + +/* Sample FD to fill in *ID. Returns true on success. + On error, returns false, with errno set. */ +static inline bool +_dl_get_file_id (int fd, struct r_file_id *id) +{ + struct stat64 st; + + if (__glibc_unlikely (__fxstat64 (_STAT_VER, fd, &st) < 0)) + return false; + + id->dev = st.st_dev; + id->ino = st.st_ino; + return true; +} + +/* Compare two results from _dl_get_file_id for equality. */ +static inline bool +_dl_file_id_match_p (const struct r_file_id *a, const struct r_file_id *b) +{ + return a->dev == b->dev && a->ino == b->ino; +} diff --git a/sysdeps/posix/dup.c b/sysdeps/posix/dup.c index fd989a072d..02d7097b4c 100644 --- a/sysdeps/posix/dup.c +++ b/sysdeps/posix/dup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/dup2.c b/sysdeps/posix/dup2.c index db7ad8e75e..ab983bcf74 100644 --- a/sysdeps/posix/dup2.c +++ b/sysdeps/posix/dup2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/euidaccess.c b/sysdeps/posix/euidaccess.c index 1cdf22b286..15340572c3 100644 --- a/sysdeps/posix/euidaccess.c +++ b/sysdeps/posix/euidaccess.c @@ -1,5 +1,5 @@ /* Check if effective user id can access file - Copyright (C) 1990-2014 Free Software Foundation, Inc. + Copyright (C) 1990-2015 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 diff --git a/sysdeps/posix/fdopendir.c b/sysdeps/posix/fdopendir.c index d8c6ec0513..3dc50a38a4 100644 --- a/sysdeps/posix/fdopendir.c +++ b/sysdeps/posix/fdopendir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2014 Free Software Foundation, Inc. +/* Copyright (C) 2005-2015 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 @@ -31,7 +31,7 @@ __fdopendir (int fd) if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0) return NULL; - if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0)) + if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) { __set_errno (ENOTDIR); return NULL; @@ -39,9 +39,9 @@ __fdopendir (int fd) /* Make sure the descriptor allows for reading. */ int flags = __fcntl (fd, F_GETFL); - if (__builtin_expect (flags == -1, 0)) + if (__glibc_unlikely (flags == -1)) return NULL; - if (__builtin_expect ((flags & O_ACCMODE) == O_WRONLY, 0)) + if (__glibc_unlikely ((flags & O_ACCMODE) == O_WRONLY)) { __set_errno (EINVAL); return NULL; diff --git a/sysdeps/posix/flock.c b/sysdeps/posix/flock.c index 72616c39b1..ba7078bdbc 100644 --- a/sysdeps/posix/flock.c +++ b/sysdeps/posix/flock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2014 Free Software Foundation, Inc. +/* Copyright (C) 1992-2015 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 diff --git a/sysdeps/posix/fpathconf.c b/sysdeps/posix/fpathconf.c index 2797fede74..25f632ee84 100644 --- a/sysdeps/posix/fpathconf.c +++ b/sysdeps/posix/fpathconf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/gai_strerror.c b/sysdeps/posix/gai_strerror.c index 1ebb42c8c1..e6d1283414 100644 --- a/sysdeps/posix/gai_strerror.c +++ b/sysdeps/posix/gai_strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2014 Free Software Foundation, Inc. +/* Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997. diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 8218237af2..31bb7e66dc 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -471,7 +471,7 @@ gaih_inet (const char *name, const struct gaih_service *service, bool malloc_namebuf = false; char *namebuf = (char *) name; - if (__builtin_expect (scope_delim != NULL, 0)) + if (__glibc_unlikely (scope_delim != NULL)) { if (malloc_name) *scope_delim = '\0'; @@ -712,6 +712,18 @@ gaih_inet (const char *name, const struct gaih_service *service, { socklen_t size = (air->family[i] == AF_INET ? INADDRSZ : IN6ADDRSZ); + + if (!((air->family[i] == AF_INET + && req->ai_family == AF_INET6 + && (req->ai_flags & AI_V4MAPPED) != 0) + || req->ai_family == AF_UNSPEC + || air->family[i] == req->ai_family)) + { + /* Skip over non-matching result. */ + addrs += size; + continue; + } + if (*pat == NULL) { *pat = addrfree++; @@ -855,8 +867,7 @@ gaih_inet (const char *name, const struct gaih_service *service, if (status != NSS_STATUS_TRYAGAIN || rc != ERANGE || herrno != NETDB_INTERNAL) { - if (status == NSS_STATUS_TRYAGAIN - && herrno == TRY_AGAIN) + if (herrno == TRY_AGAIN) no_data = EAI_AGAIN; else no_data = herrno == NO_DATA; @@ -2608,18 +2619,18 @@ getaddrinfo (const char *name, const char *service, the information. */ struct sort_result_combo src = { .results = results, .nresults = nresults }; - if (__builtin_expect (gaiconf_reload_flag_ever_set, 0)) + if (__glibc_unlikely (gaiconf_reload_flag_ever_set)) { __libc_lock_define_initialized (static, lock); __libc_lock_lock (lock); if (__libc_once_get (old_once) && gaiconf_reload_flag) gaiconf_reload (); - qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src); + __qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src); __libc_lock_unlock (lock); } else - qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src); + __qsort_r (order, nresults, sizeof (order[0]), rfc3484_sort, &src); /* Queue the results up as they come out of sorting. */ q = p = results[order[0]].dest_addr; diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c index 61924d5748..afe696767a 100644 --- a/sysdeps/posix/getcwd.c +++ b/sysdeps/posix/getcwd.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -195,6 +195,10 @@ extern char *alloca (); #ifndef __GNU_LIBRARY__ # define __lstat64 stat64 #endif + +#ifndef _LIBC +# define __rewinddir rewinddir +#endif #ifndef _LIBC # define __getcwd getcwd @@ -206,7 +210,7 @@ extern char *alloca (); #ifdef __ASSUME_ATFCTS # define __have_atfcts 1 -#elif defined NOT_IN_libc && defined IS_IN_rtld +#elif IS_IN (rtld) static int __rtld_have_atfcts; # define __have_atfcts __rtld_have_atfcts #endif @@ -390,7 +394,7 @@ __getcwd (buf, size) if (use_d_ino) { use_d_ino = false; - rewinddir (dirstream); + __rewinddir (dirstream); continue; } diff --git a/sysdeps/posix/getdtsz.c b/sysdeps/posix/getdtsz.c index 96e6991216..431b5d666e 100644 --- a/sysdeps/posix/getdtsz.c +++ b/sysdeps/posix/getdtsz.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/gethostname.c b/sysdeps/posix/gethostname.c index 5393e92be7..49177059c6 100644 --- a/sysdeps/posix/gethostname.c +++ b/sysdeps/posix/gethostname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2014 Free Software Foundation, Inc. +/* Copyright (C) 1992-2015 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 diff --git a/sysdeps/posix/getpagesize.c b/sysdeps/posix/getpagesize.c index 31eae75799..112b59b325 100644 --- a/sysdeps/posix/getpagesize.c +++ b/sysdeps/posix/getpagesize.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993-2014 Free Software Foundation, Inc. +/* Copyright (C) 1993-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Brendan Kehoe (brendan@cygnus.com). diff --git a/sysdeps/posix/gettimeofday.c b/sysdeps/posix/gettimeofday.c index 529cdf773d..018acdfd0a 100644 --- a/sysdeps/posix/gettimeofday.c +++ b/sysdeps/posix/gettimeofday.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/isatty.c b/sysdeps/posix/isatty.c index 781ce29fdc..807631a484 100644 --- a/sysdeps/posix/isatty.c +++ b/sysdeps/posix/isatty.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/isfdtype.c b/sysdeps/posix/isfdtype.c index 5328e6de15..98d424f7d6 100644 --- a/sysdeps/posix/isfdtype.c +++ b/sysdeps/posix/isfdtype.c @@ -1,5 +1,5 @@ /* Determine whether descriptor has given property. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/sysdeps/posix/killpg.c b/sysdeps/posix/killpg.c index 4c275a4c2e..77ffc7c1d8 100644 --- a/sysdeps/posix/killpg.c +++ b/sysdeps/posix/killpg.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 74e40ee4d2..2d99c46cf8 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -1,5 +1,5 @@ /* Catastrophic failure reports. Generic POSIX.1 version. - Copyright (C) 1993-2014 Free Software Foundation, Inc. + Copyright (C) 1993-2015 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 diff --git a/sysdeps/posix/mkfifo.c b/sysdeps/posix/mkfifo.c index cdb2f5d967..31fac04c65 100644 --- a/sysdeps/posix/mkfifo.c +++ b/sysdeps/posix/mkfifo.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/mkfifoat.c b/sysdeps/posix/mkfifoat.c index ab269e9535..c7770eb60d 100644 --- a/sysdeps/posix/mkfifoat.c +++ b/sysdeps/posix/mkfifoat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005-2014 Free Software Foundation, Inc. +/* Copyright (C) 2005-2015 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 diff --git a/sysdeps/posix/nice.c b/sysdeps/posix/nice.c index 087b22cced..42bb99b7e1 100644 --- a/sysdeps/posix/nice.c +++ b/sysdeps/posix/nice.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2014 Free Software Foundation, Inc. +/* Copyright (C) 1992-2015 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 @@ -31,7 +31,7 @@ nice (int incr) /* -1 is a valid priority, so we use errno to check for an error. */ save = errno; __set_errno (0); - prio = getpriority (PRIO_PROCESS, 0); + prio = __getpriority (PRIO_PROCESS, 0); if (prio == -1) { if (errno != 0) @@ -40,12 +40,12 @@ nice (int incr) __set_errno (save); } - result = setpriority (PRIO_PROCESS, 0, prio + incr); + result = __setpriority (PRIO_PROCESS, 0, prio + incr); if (result == -1) { if (errno == EACCES) errno = EPERM; return -1; } - return getpriority (PRIO_PROCESS, 0); + return __getpriority (PRIO_PROCESS, 0); } diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c index 64d192af97..74f669f408 100644 --- a/sysdeps/posix/open64.c +++ b/sysdeps/posix/open64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -19,14 +19,14 @@ #include <stdarg.h> #include <sysdep-cancel.h> -/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, +/* Open FILE with access OFLAG. If O_CREAT or O_TMPFILE is in OFLAG, a third argument is the file protection. */ int __libc_open64 (const char *file, int oflag, ...) { int mode = 0; - if (oflag & O_CREAT) + if (__OPEN_NEEDS_MODE (oflag)) { va_list arg; va_start (arg, oflag); diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c index e366701bd4..6509f5c05c 100644 --- a/sysdeps/posix/opendir.c +++ b/sysdeps/posix/opendir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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,6 +18,7 @@ #include <assert.h> #include <errno.h> #include <limits.h> +#include <stdbool.h> #include <stddef.h> #include <stdlib.h> #include <dirent.h> @@ -81,83 +82,122 @@ tryopen_o_directory (void) #endif -DIR * -internal_function -__opendirat (int dfd, const char *name) +static bool +invalid_name (const char *name) { - struct stat64 statbuf; - struct stat64 *statp = NULL; - - if (__builtin_expect (name[0], '\1') == '\0') + if (__glibc_unlikely (name[0] == '\0')) { /* POSIX.1-1990 says an empty name gets ENOENT; but `open' might like it fine. */ __set_errno (ENOENT); - return NULL; + return true; } + return false; +} + +static bool +need_isdir_precheck (void) +{ #ifdef O_DIRECTORY /* Test whether O_DIRECTORY works. */ if (o_directory_works == 0) tryopen_o_directory (); /* We can skip the expensive `stat' call if O_DIRECTORY works. */ - if (o_directory_works < 0) + return o_directory_works > 0; #endif - { - /* We first have to check whether the name is for a directory. We - cannot do this after the open() call since the open/close operation - performed on, say, a tape device might have undesirable effects. */ - if (__builtin_expect (__xstat64 (_STAT_VER, name, &statbuf), 0) < 0) - return NULL; - if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0)) - { - __set_errno (ENOTDIR); - return NULL; - } - } + return true; +} + +static int +opendir_oflags (void) +{ int flags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE; #ifdef O_CLOEXEC flags |= O_CLOEXEC; #endif - int fd; -#ifdef IS_IN_rtld - assert (dfd == AT_FDCWD); - fd = open_not_cancel_2 (name, flags); -#else - fd = openat_not_cancel_3 (dfd, name, flags); -#endif - if (__builtin_expect (fd, 0) < 0) + return flags; +} + + +static DIR * +opendir_tail (int fd) +{ + if (__glibc_unlikely (fd < 0)) return NULL; -#ifdef O_DIRECTORY - if (o_directory_works <= 0) -#endif + /* Now make sure this really is a directory and nothing changed since the + `stat' call. The S_ISDIR check is superfluous if O_DIRECTORY works, + but it's cheap and we need the stat call for st_blksize anyway. */ + struct stat64 statbuf; + if (__glibc_unlikely (__fxstat64 (_STAT_VER, fd, &statbuf) < 0)) + goto lose; + if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) { - /* Now make sure this really is a directory and nothing changed since - the `stat' call. */ - if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &statbuf), 0) < 0) - goto lose; - if (__builtin_expect (! S_ISDIR (statbuf.st_mode), 0)) + __set_errno (ENOTDIR); + lose: + close_not_cancel_no_status (fd); + return NULL; + } + + return __alloc_dir (fd, true, 0, &statbuf); +} + + +#if IS_IN (libc) +DIR * +internal_function +__opendirat (int dfd, const char *name) +{ + if (__glibc_unlikely (invalid_name (name))) + return NULL; + + if (need_isdir_precheck ()) + { + /* We first have to check whether the name is for a directory. We + cannot do this after the open() call since the open/close operation + performed on, say, a tape device might have undesirable effects. */ + struct stat64 statbuf; + if (__glibc_unlikely (__fxstatat64 (_STAT_VER, dfd, name, + &statbuf, 0) < 0)) + return NULL; + if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) { __set_errno (ENOTDIR); - lose: - close_not_cancel_no_status (fd); return NULL; } - statp = &statbuf; } - return __alloc_dir (fd, true, 0, statp); + return opendir_tail (openat_not_cancel_3 (dfd, name, opendir_oflags ())); } +#endif /* Open a directory stream on NAME. */ DIR * __opendir (const char *name) { - return __opendirat (AT_FDCWD, name); + if (__glibc_unlikely (invalid_name (name))) + return NULL; + + if (need_isdir_precheck ()) + { + /* We first have to check whether the name is for a directory. We + cannot do this after the open() call since the open/close operation + performed on, say, a tape device might have undesirable effects. */ + struct stat64 statbuf; + if (__glibc_unlikely (__xstat64 (_STAT_VER, name, &statbuf) < 0)) + return NULL; + if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) + { + __set_errno (ENOTDIR); + return NULL; + } + } + + return opendir_tail (open_not_cancel_2 (name, opendir_oflags ())); } weak_alias (__opendir, opendir) @@ -224,7 +264,7 @@ __alloc_dir (int fd, bool close_fd, int flags, const struct stat64 *statp) } dirp->fd = fd; -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_init (dirp->lock); #endif dirp->allocation = allocation; diff --git a/sysdeps/posix/pathconf.c b/sysdeps/posix/pathconf.c index 8aa55e0856..ff77f0662c 100644 --- a/sysdeps/posix/pathconf.c +++ b/sysdeps/posix/pathconf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -65,10 +65,10 @@ __pathconf (const char *path, int name) case _PC_NAME_MAX: #ifdef NAME_MAX { - struct statfs buf; + struct statvfs64 sv; int save_errno = errno; - if (__statfs (path, &buf) < 0) + if (__statvfs64 (path, &sv) < 0) { if (errno == ENOSYS) { @@ -79,15 +79,7 @@ __pathconf (const char *path, int name) } else { -#ifdef _STATFS_F_NAMELEN - return buf.f_namelen; -#else -# ifdef _STATFS_F_NAME_MAX - return buf.f_name_max; -# else - return NAME_MAX; -# endif -#endif + return sv.f_namemax; } } #else diff --git a/sysdeps/posix/pause.c b/sysdeps/posix/pause.c index 6d3bfc5c46..6ba4d42281 100644 --- a/sysdeps/posix/pause.c +++ b/sysdeps/posix/pause.c @@ -1,5 +1,5 @@ /* pause -- suspend the process until a signal arrives. POSIX.1 version. - Copyright (C) 2003-2014 Free Software Foundation, Inc. + Copyright (C) 2003-2015 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 diff --git a/sysdeps/posix/posix_fallocate.c b/sysdeps/posix/posix_fallocate.c index fc5f8833ea..e7fe201b68 100644 --- a/sysdeps/posix/posix_fallocate.c +++ b/sysdeps/posix/posix_fallocate.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2014 Free Software Foundation, Inc. +/* Copyright (C) 2000-2015 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,26 +18,36 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> +#include <stdint.h> +#include <sys/fcntl.h> #include <sys/stat.h> #include <sys/statfs.h> -/* Reserve storage for the data of the file associated with FD. */ +/* Reserve storage for the data of the file associated with FD. This + emulation is far from perfect, but the kernel cannot do not much + better for network file systems, either. */ int posix_fallocate (int fd, __off_t offset, __off_t len) { struct stat64 st; - struct statfs f; - /* `off_t' is a signed type. Therefore we can determine whether - OFFSET + LEN is too large if it is a negative value. */ if (offset < 0 || len < 0) return EINVAL; - if (offset + len < 0) + + /* Perform overflow check. The outer cast relies on a GCC + extension. */ + if ((__off_t) ((uint64_t) offset) + ((uint64_t) len) < 0) return EFBIG; - /* First thing we have to make sure is that this is really a regular - file. */ + /* pwrite below will not do the right thing in O_APPEND mode. */ + { + int flags = __fcntl (fd, F_GETFL, 0); + if (flags < 0 || (flags & O_APPEND) != 0) + return EBADF; + } + + /* We have to make sure that this is really a regular file. */ if (__fxstat64 (_STAT_VER, fd, &st) != 0) return EBADF; if (S_ISFIFO (st.st_mode)) @@ -47,6 +57,8 @@ posix_fallocate (int fd, __off_t offset, __off_t len) if (len == 0) { + /* This is racy, but there is no good way to satisfy a + zero-length allocation request. */ if (st.st_size < offset) { int ret = __ftruncate (fd, offset); @@ -58,19 +70,36 @@ posix_fallocate (int fd, __off_t offset, __off_t len) return 0; } - /* We have to know the block size of the filesystem to get at least some - sort of performance. */ - if (__fstatfs (fd, &f) != 0) - return errno; - - /* Try to play safe. */ - if (f.f_bsize == 0) - f.f_bsize = 512; - - /* Write something to every block. */ - for (offset += (len - 1) % f.f_bsize; len > 0; offset += f.f_bsize) + /* Minimize data transfer for network file systems, by issuing + single-byte write requests spaced by the file system block size. + (Most local file systems have fallocate support, so this fallback + code is not used there.) */ + + unsigned increment; + { + struct statfs64 f; + + if (__fstatfs64 (fd, &f) != 0) + return errno; + if (f.f_bsize == 0) + increment = 512; + else if (f.f_bsize < 4096) + increment = f.f_bsize; + else + /* NFS does not propagate the block size of the underlying + storage and may report a much larger value which would still + leave holes after the loop below, so we cap the increment at + 4096. */ + increment = 4096; + } + + /* Write a null byte to every block. This is racy; we currently + lack a better option. Compare-and-swap against a file mapping + might additional local races, but requires interposition of a + signal handler to catch SIGBUS. */ + for (offset += (len - 1) % increment; len > 0; offset += increment) { - len -= f.f_bsize; + len -= increment; if (offset < st.st_size) { diff --git a/sysdeps/posix/posix_fallocate64.c b/sysdeps/posix/posix_fallocate64.c index 729e84cddf..ee32679a05 100644 --- a/sysdeps/posix/posix_fallocate64.c +++ b/sysdeps/posix/posix_fallocate64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2014 Free Software Foundation, Inc. +/* Copyright (C) 2000-2015 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,26 +18,36 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> +#include <stdint.h> +#include <sys/fcntl.h> #include <sys/stat.h> #include <sys/statfs.h> -/* Reserve storage for the data of the file associated with FD. */ +/* Reserve storage for the data of the file associated with FD. This + emulation is far from perfect, but the kernel cannot do not much + better for network file systems, either. */ int __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len) { struct stat64 st; - struct statfs64 f; - /* `off64_t' is a signed type. Therefore we can determine whether - OFFSET + LEN is too large if it is a negative value. */ if (offset < 0 || len < 0) return EINVAL; - if (offset + len < 0) + + /* Perform overflow check. The outer cast relies on a GCC + extension. */ + if ((__off64_t) ((uint64_t) offset) + ((uint64_t) len) < 0) return EFBIG; - /* First thing we have to make sure is that this is really a regular - file. */ + /* pwrite64 below will not do the right thing in O_APPEND mode. */ + { + int flags = __fcntl (fd, F_GETFL, 0); + if (flags < 0 || (flags & O_APPEND) != 0) + return EBADF; + } + + /* We have to make sure that this is really a regular file. */ if (__fxstat64 (_STAT_VER, fd, &st) != 0) return EBADF; if (S_ISFIFO (st.st_mode)) @@ -47,6 +57,8 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len) if (len == 0) { + /* This is racy, but there is no good way to satisfy a + zero-length allocation request. */ if (st.st_size < offset) { int ret = __ftruncate64 (fd, offset); @@ -58,19 +70,36 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len) return 0; } - /* We have to know the block size of the filesystem to get at least some - sort of performance. */ - if (__fstatfs64 (fd, &f) != 0) - return errno; - - /* Try to play safe. */ - if (f.f_bsize == 0) - f.f_bsize = 512; - - /* Write something to every block. */ - for (offset += (len - 1) % f.f_bsize; len > 0; offset += f.f_bsize) + /* Minimize data transfer for network file systems, by issuing + single-byte write requests spaced by the file system block size. + (Most local file systems have fallocate support, so this fallback + code is not used there.) */ + + unsigned increment; + { + struct statfs64 f; + + if (__fstatfs64 (fd, &f) != 0) + return errno; + if (f.f_bsize == 0) + increment = 512; + else if (f.f_bsize < 4096) + increment = f.f_bsize; + else + /* NFS clients do not propagate the block size of the underlying + storage and may report a much larger value which would still + leave holes after the loop below, so we cap the increment at + 4096. */ + increment = 4096; + } + + /* Write a null byte to every block. This is racy; we currently + lack a better option. Compare-and-swap against a file mapping + might address local races, but requires interposition of a signal + handler to catch SIGBUS. */ + for (offset += (len - 1) % increment; len > 0; offset += increment) { - len -= f.f_bsize; + len -= increment; if (offset < st.st_size) { diff --git a/sysdeps/posix/pread.c b/sysdeps/posix/pread.c index 7f5cfa12ef..84bce25288 100644 --- a/sysdeps/posix/pread.c +++ b/sysdeps/posix/pread.c @@ -1,6 +1,6 @@ /* Read block from given position in file without changing file pointer. POSIX version. - Copyright (C) 1997-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/sysdeps/posix/pread64.c b/sysdeps/posix/pread64.c index 36b53f7b32..c17e97676e 100644 --- a/sysdeps/posix/pread64.c +++ b/sysdeps/posix/pread64.c @@ -1,6 +1,6 @@ /* Read block from given position in file without changing file pointer. POSIX version. - Copyright (C) 1997-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/sysdeps/posix/preadv.c b/sysdeps/posix/preadv.c index b1fd060b30..4540bd1e2d 100644 --- a/sysdeps/posix/preadv.c +++ b/sysdeps/posix/preadv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2014 Free Software Foundation, Inc. +/* Copyright (C) 2009-2015 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 diff --git a/sysdeps/posix/profil.c b/sysdeps/posix/profil.c index 696c7a6cad..5210470d5c 100644 --- a/sysdeps/posix/profil.c +++ b/sysdeps/posix/profil.c @@ -1,5 +1,5 @@ /* Low-level statistical profiling support function. Mostly POSIX.1 version. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -48,7 +48,7 @@ profil_count (void *pc) ++samples[i]; } -/* Get the machine-dependent definition of `profil_counter', the signal +/* Get the machine-dependent definition of `__profil_counter', the signal handler for SIGPROF. It calls `profil_count' (above) with the PC of the interrupted code. */ #include "profil-counter.h" @@ -64,7 +64,7 @@ __profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale) { struct sigaction act; struct itimerval timer; -#ifndef IS_IN_rtld +#if !IS_IN (rtld) static struct sigaction oact; static struct itimerval otimer; # define oact_ptr &oact @@ -103,7 +103,7 @@ __profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale) pc_offset = offset; pc_scale = scale; - act.sa_handler = (sighandler_t) &profil_counter; + act.sa_handler = (sighandler_t) &__profil_counter; act.sa_flags = SA_RESTART; __sigfillset (&act.sa_mask); if (__sigaction (SIGPROF, &act, oact_ptr) < 0) diff --git a/sysdeps/posix/pwrite.c b/sysdeps/posix/pwrite.c index 4a9fe1071c..143ba86146 100644 --- a/sysdeps/posix/pwrite.c +++ b/sysdeps/posix/pwrite.c @@ -1,6 +1,6 @@ /* Write block to given position in file without changing file pointer. POSIX version. - Copyright (C) 1997-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/sysdeps/posix/pwrite64.c b/sysdeps/posix/pwrite64.c index 18c4e55983..f501d5175e 100644 --- a/sysdeps/posix/pwrite64.c +++ b/sysdeps/posix/pwrite64.c @@ -1,6 +1,6 @@ /* Write block to given position in file without changing file pointer. POSIX version. - Copyright (C) 1997-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/sysdeps/posix/pwritev.c b/sysdeps/posix/pwritev.c index 97b7523137..772e3cb105 100644 --- a/sysdeps/posix/pwritev.c +++ b/sysdeps/posix/pwritev.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2014 Free Software Foundation, Inc. +/* Copyright (C) 2009-2015 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 diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c index f2424f9c4a..008f87b556 100644 --- a/sysdeps/posix/raise.c +++ b/sysdeps/posix/raise.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/readdir.c b/sysdeps/posix/readdir.c index 7bb956a916..dbd552b902 100644 --- a/sysdeps/posix/readdir.c +++ b/sysdeps/posix/readdir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -40,7 +40,7 @@ __READDIR (DIR *dirp) DIRENT_TYPE *dp; int saved_errno = errno; -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_lock (dirp->lock); #endif @@ -110,7 +110,7 @@ __READDIR (DIR *dirp) /* Skip deleted files. */ } while (dp->d_ino == 0); -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_unlock (dirp->lock); #endif diff --git a/sysdeps/posix/readdir_r.c b/sysdeps/posix/readdir_r.c index ee88c9b46d..0dd87651c3 100644 --- a/sysdeps/posix/readdir_r.c +++ b/sysdeps/posix/readdir_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/readv.c b/sysdeps/posix/readv.c index b7a8e1e7c2..2d11d191b5 100644 --- a/sysdeps/posix/readv.c +++ b/sysdeps/posix/readv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -37,7 +37,7 @@ ifree (char **ptrp) Operates just like 'read' (see <unistd.h>) except that data are put in VECTOR instead of a contiguous buffer. */ ssize_t -__libc_readv (int fd, const struct iovec *vector, int count) +__readv (int fd, const struct iovec *vector, int count) { /* Find the total number of bytes to be read. */ size_t bytes = 0; @@ -88,7 +88,4 @@ __libc_readv (int fd, const struct iovec *vector, int count) return bytes_read; } -#ifndef __libc_readv -strong_alias (__libc_readv, __readv) -weak_alias (__libc_readv, readv) -#endif +weak_alias (__readv, readv) diff --git a/sysdeps/posix/remove.c b/sysdeps/posix/remove.c index dc7f78d86f..4ae3cfb4ba 100644 --- a/sysdeps/posix/remove.c +++ b/sysdeps/posix/remove.c @@ -1,5 +1,5 @@ /* ANSI C `remove' function to delete a file or directory. POSIX.1 version. - Copyright (C) 1995-2014 Free Software Foundation, Inc. + Copyright (C) 1995-2015 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 diff --git a/sysdeps/posix/rename.c b/sysdeps/posix/rename.c index a50fc387be..0f13abbf5d 100644 --- a/sysdeps/posix/rename.c +++ b/sysdeps/posix/rename.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/rewinddir.c b/sysdeps/posix/rewinddir.c index 5a4a7154ab..5ac4897f7d 100644 --- a/sysdeps/posix/rewinddir.c +++ b/sysdeps/posix/rewinddir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -23,10 +23,10 @@ /* Rewind DIRP to the beginning of the directory. */ void -rewinddir (dirp) +__rewinddir (dirp) DIR *dirp; { -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_lock (dirp->lock); #endif (void) __lseek (dirp->fd, (off_t) 0, SEEK_SET); @@ -34,8 +34,9 @@ rewinddir (dirp) dirp->offset = 0; dirp->size = 0; dirp->errcode = 0; -#ifndef NOT_IN_libc +#if IS_IN (libc) __libc_lock_unlock (dirp->lock); #endif } -libc_hidden_def (rewinddir) +libc_hidden_def (__rewinddir) +weak_alias (__rewinddir, rewinddir) diff --git a/sysdeps/posix/seekdir.c b/sysdeps/posix/seekdir.c index a143f69895..f15a57cf70 100644 --- a/sysdeps/posix/seekdir.c +++ b/sysdeps/posix/seekdir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/shm-directory.c b/sysdeps/posix/shm-directory.c new file mode 100644 index 0000000000..2c0f918d9f --- /dev/null +++ b/sysdeps/posix/shm-directory.c @@ -0,0 +1,38 @@ +/* Determine directory for shm/sem files. Generic POSIX version. + Copyright (C) 2014-2015 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <shm-directory.h> +#include <unistd.h> + +#if _POSIX_MAPPED_FILES + +# include <paths.h> + +# define SHMDIR (_PATH_DEV "shm/") + +const char * +__shm_directory (size_t *len) +{ + *len = sizeof SHMDIR - 1; + return SHMDIR; +} +# if IS_IN (libpthread) +hidden_def (__shm_directory) +# endif + +#endif diff --git a/sysdeps/posix/shm-directory.h b/sysdeps/posix/shm-directory.h new file mode 100644 index 0000000000..d209425c77 --- /dev/null +++ b/sysdeps/posix/shm-directory.h @@ -0,0 +1,66 @@ +/* Header for directory for shm/sem files. + Copyright (C) 2014-2015 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SHM_DIRECTORY_H + +#include <errno.h> +#include <limits.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +extern const char *__shm_directory (size_t *len); + +/* This defines local variables SHM_DIR and SHM_DIRLEN, giving the + directory prefix (with trailing slash) and length (not including '\0' + terminator) of the directory used for shm files. If that cannot be + determined, it sets errno to ENOSYS and returns RETVAL_FOR_INVALID. + + This uses the local variable NAME as an lvalue, and increments it past + any leading slashes. It then defines the local variable NAMELEN, giving + strlen (NAME) + 1. If NAME is invalid, it sets errno to + ERRNO_FOR_INVALID and returns RETVAL_FOR_INVALID. Finally, it defines + the local variable SHM_NAME, giving the absolute file name of the shm + file corresponding to NAME. PREFIX is a string constant used as a + prefix on NAME. */ + +#define SHM_GET_NAME(errno_for_invalid, retval_for_invalid, prefix) \ + size_t shm_dirlen; \ + const char *shm_dir = __shm_directory (&shm_dirlen); \ + /* If we don't know what directory to use, there is nothing we can do. */ \ + if (__glibc_unlikely (shm_dir == NULL)) \ + { \ + __set_errno (ENOSYS); \ + return retval_for_invalid; \ + } \ + /* Construct the filename. */ \ + while (name[0] == '/') \ + ++name; \ + size_t namelen = strlen (name) + 1; \ + /* Validate the filename. */ \ + if (namelen == 1 || namelen >= NAME_MAX || strchr (name, '/') != NULL) \ + { \ + __set_errno (errno_for_invalid); \ + return retval_for_invalid; \ + } \ + char *shm_name = __alloca (shm_dirlen + sizeof prefix - 1 + namelen); \ + __mempcpy (__mempcpy (__mempcpy (shm_name, shm_dir, shm_dirlen), \ + prefix, sizeof prefix - 1), \ + name, namelen) + +#endif /* shm-directory.h */ diff --git a/sysdeps/posix/shm_open.c b/sysdeps/posix/shm_open.c index 456b3d8b8f..3a5f07bbac 100644 --- a/sysdeps/posix/shm_open.c +++ b/sysdeps/posix/shm_open.c @@ -1,5 +1,5 @@ /* shm_open -- open a POSIX shared memory object. Generic POSIX file version. - Copyright (C) 2001-2014 Free Software Foundation, Inc. + Copyright (C) 2001-2015 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 @@ -19,50 +19,41 @@ #include <unistd.h> #if ! _POSIX_MAPPED_FILES -#include <rt/shm_open.c> + +# include <rt/shm_open.c> #else -#include <errno.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <string.h> -#include <stdlib.h> -#include <paths.h> +# include <fcntl.h> +# include <shm-directory.h> -#define SHMDIR (_PATH_DEV "shm/") /* Open shared memory object. */ int shm_open (const char *name, int oflag, mode_t mode) { - size_t namelen; - char *fname; - int fd; - - /* Construct the filename. */ - while (name[0] == '/') - ++name; - - if (name[0] == '\0') - { - /* The name "/" is not supported. */ - __set_errno (EINVAL); - return -1; - } - - namelen = strlen (name); - fname = (char *) __alloca (sizeof SHMDIR - 1 + namelen + 1); - __mempcpy (__mempcpy (fname, SHMDIR, sizeof SHMDIR - 1), - name, namelen + 1); - - fd = open (name, oflag, mode); + SHM_GET_NAME (EINVAL, -1, ""); + +# ifdef O_NOFOLLOW + oflag |= O_NOFOLLOW; +# endif +# ifdef O_CLOEXEC + oflag |= O_CLOEXEC; +# endif + int fd = open (shm_name, oflag, mode); + if (fd == -1 && __glibc_unlikely (errno == EISDIR)) + /* It might be better to fold this error with EINVAL since + directory names are just another example for unsuitable shared + object names and the standard does not mention EISDIR. */ + __set_errno (EINVAL); + +# ifndef O_CLOEXEC if (fd != -1) { /* We got a descriptor. Now set the FD_CLOEXEC bit. */ int flags = fcntl (fd, F_GETFD, 0); - if (__builtin_expect (flags, 0) != -1) + if (__glibc_likely (flags != -1)) { flags |= FD_CLOEXEC; flags = fcntl (fd, F_SETFD, flags); @@ -77,8 +68,9 @@ shm_open (const char *name, int oflag, mode_t mode) __set_errno (save_errno); } } +# endif return fd; } -#endif +#endif /* _POSIX_MAPPED_FILES */ diff --git a/sysdeps/posix/shm_unlink.c b/sysdeps/posix/shm_unlink.c index dc94e1692b..fae8d99525 100644 --- a/sysdeps/posix/shm_unlink.c +++ b/sysdeps/posix/shm_unlink.c @@ -1,5 +1,5 @@ /* shm_unlink -- remove a POSIX shared memory object. Generic POSIX version. - Copyright (C) 2001-2014 Free Software Foundation, Inc. + Copyright (C) 2001-2015 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 @@ -24,37 +24,20 @@ #else #include <errno.h> -#include <sys/mman.h> #include <string.h> -#include <stdlib.h> -#include <paths.h> +#include "shm-directory.h" -#define SHMDIR (_PATH_DEV "shm/") /* Remove shared memory object. */ int shm_unlink (const char *name) { - size_t namelen; - char *fname; - - /* Construct the filename. */ - while (name[0] == '/') - ++name; - - if (name[0] == '\0') - { - /* The name "/" is not supported. */ - __set_errno (EINVAL); - return -1; - } - - namelen = strlen (name); - fname = (char *) __alloca (sizeof SHMDIR - 1 + namelen + 1); - __mempcpy (__mempcpy (fname, SHMDIR, sizeof SHMDIR - 1), - name, namelen + 1); - - return unlink (name); + SHM_GET_NAME (ENOENT, -1, ""); + + int result = unlink (shm_name); + if (result < 0 && errno == EPERM) + __set_errno (EACCES); + return result; } #endif diff --git a/sysdeps/posix/sigblock.c b/sysdeps/posix/sigblock.c index 5d0086223f..3392fbf3ea 100644 --- a/sysdeps/posix/sigblock.c +++ b/sysdeps/posix/sigblock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sigignore.c b/sysdeps/posix/sigignore.c index 4e232cc40f..0c8c10dbc5 100644 --- a/sysdeps/posix/sigignore.c +++ b/sysdeps/posix/sigignore.c @@ -1,5 +1,5 @@ /* Set the disposition of SIG to SIG_IGN. - Copyright (C) 1998-2014 Free Software Foundation, Inc. + Copyright (C) 1998-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. diff --git a/sysdeps/posix/sigintr.c b/sysdeps/posix/sigintr.c index 200836438e..28c9052d47 100644 --- a/sysdeps/posix/sigintr.c +++ b/sysdeps/posix/sigintr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2014 Free Software Foundation, Inc. +/* Copyright (C) 1992-2015 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 diff --git a/sysdeps/posix/signal.c b/sysdeps/posix/signal.c index 934fffb50b..0c588238f3 100644 --- a/sysdeps/posix/signal.c +++ b/sysdeps/posix/signal.c @@ -1,5 +1,5 @@ /* BSD-like signal function. - Copyright (C) 1991-2014 Free Software Foundation, Inc. + Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sigpause.c b/sysdeps/posix/sigpause.c index 3dcf86c43c..662640dc26 100644 --- a/sysdeps/posix/sigpause.c +++ b/sysdeps/posix/sigpause.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sigset.c b/sysdeps/posix/sigset.c index 8542e28c21..35c9fcd607 100644 --- a/sysdeps/posix/sigset.c +++ b/sysdeps/posix/sigset.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2014 Free Software Foundation, Inc. +/* Copyright (C) 1998-2015 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 diff --git a/sysdeps/posix/sigsetmask.c b/sysdeps/posix/sigsetmask.c index a36e75fb0e..94af0baf2c 100644 --- a/sysdeps/posix/sigsetmask.c +++ b/sysdeps/posix/sigsetmask.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sigsuspend.c b/sysdeps/posix/sigsuspend.c index 3e0374c7a7..1ac689f6fb 100644 --- a/sysdeps/posix/sigsuspend.c +++ b/sysdeps/posix/sigsuspend.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sigvec.c b/sysdeps/posix/sigvec.c deleted file mode 100644 index 83ba75546f..0000000000 --- a/sysdeps/posix/sigvec.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright (C) 1991-2014 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 Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#include <signal.h> -#include <errno.h> -#include <stddef.h> - -/* Include macros to convert between `sigset_t' and old-style mask. */ -#include <sigset-cvt-mask.h> - -#ifndef SA_RESETHAND -/* When sigaction lacks the extension bit for it, - we use a wrapper handler to support SV_RESETHAND. */ -struct sigvec_wrapper_data -{ - __sighandler_t sw_handler; - unsigned int sw_mask; -}; - -static void sigvec_wrapper_handler (int sig) __THROW; - -static struct sigvec_wrapper_data sigvec_wrapper_data[NSIG]; -#endif - - -/* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member - of VEC. The signals in `sv_mask' will be blocked while the handler runs. - If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be - reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL, - it is filled in with the old information for SIG. */ -int -__sigvec (sig, vec, ovec) - int sig; - const struct sigvec *vec; - struct sigvec *ovec; -{ - struct sigaction old; - -#ifndef SA_RESETHAND - if (vec == NULL || !(vec->sv_flags & SV_RESETHAND)) -#endif - { - struct sigaction new, *n; - - if (vec == NULL) - n = NULL; - else - { - __sighandler_t handler; - unsigned int mask; - unsigned int sv_flags; - unsigned int sa_flags; - - handler = vec->sv_handler; - mask = vec->sv_mask; - sv_flags = vec->sv_flags; - sa_flags = 0; - if (sv_flags & SV_ONSTACK) - { -#ifdef SA_ONSTACK - sa_flags |= SA_ONSTACK; -#else - __set_errno (ENOSYS); - return -1; -#endif - } -#ifdef SA_RESTART - if (!(sv_flags & SV_INTERRUPT)) - sa_flags |= SA_RESTART; -#endif -#ifdef SA_RESETHAND - if (sv_flags & SV_RESETHAND) - sa_flags |= SA_RESETHAND; -#endif - n = &new; - new.sa_handler = handler; - if (sigset_set_old_mask (&new.sa_mask, mask) < 0) - return -1; - new.sa_flags = sa_flags; - } - - if (__sigaction (sig, n, &old) < 0) - return -1; - } -#ifndef SA_RESETHAND - else - { - __sighandler_t handler; - unsigned int mask; - struct sigvec_wrapper_data *data; - struct sigaction wrapper; - - handler = vec->sv_handler; - mask = (unsigned int)vec->sv_mask; - data = &sigvec_wrapper_data[sig]; - wrapper.sa_handler = sigvec_wrapper_handler; - /* FIXME: should we set wrapper.sa_mask, wrapper.sa_flags?? */ - data->sw_handler = handler; - data->sw_mask = mask; - - if (__sigaction (sig, &wrapper, &old) < 0) - return -1; - } -#endif - - if (ovec != NULL) - { - __sighandler_t handler; - unsigned int sv_flags; - unsigned int sa_flags; - unsigned int mask; - - handler = old.sa_handler; - sv_flags = 0; - sa_flags = old.sa_flags; -#ifndef SA_RESETHAND - if (handler == sigvec_wrapper_handler) - { - handler = sigvec_wrapper_data[sig].sw_handler; - /* should we use data->sw_mask?? */ - sv_flags |= SV_RESETHAND; - } -#else - if (sa_flags & SA_RESETHAND) - sv_flags |= SV_RESETHAND; -#endif - mask = sigset_get_old_mask (&old.sa_mask); -#ifdef SA_ONSTACK - if (sa_flags & SA_ONSTACK) - sv_flags |= SV_ONSTACK; -#endif -#ifdef SA_RESTART - if (!(sa_flags & SA_RESTART)) -#endif - sv_flags |= SV_INTERRUPT; - ovec->sv_handler = handler; - ovec->sv_mask = (int)mask; - ovec->sv_flags = (int)sv_flags; - } - - return 0; -} - -weak_alias (__sigvec, sigvec) - -#ifndef SA_RESETHAND -static void -sigvec_wrapper_handler (sig) - int sig; -{ - struct sigvec_wrapper_data *data; - struct sigaction act; - int save; - __sighandler_t handler; - - data = &sigvec_wrapper_data[sig]; - act.sa_handler = SIG_DFL; - act.sa_flags = 0; - sigset_set_old_mask (&act.sa_mask, data->sw_mask); - handler = data->sw_handler; - save = errno; - (void) __sigaction (sig, &act, (struct sigaction *) NULL); - __set_errno (save); - - (*handler) (sig); -} -#endif diff --git a/sysdeps/posix/sigwait.c b/sysdeps/posix/sigwait.c index 313eb18250..8dc550bfb7 100644 --- a/sysdeps/posix/sigwait.c +++ b/sysdeps/posix/sigwait.c @@ -1,5 +1,5 @@ /* Implementation of sigwait function from POSIX.1c. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/sysdeps/posix/sleep.c b/sysdeps/posix/sleep.c index 4a72c275b3..75d9c18cd3 100644 --- a/sysdeps/posix/sleep.c +++ b/sysdeps/posix/sleep.c @@ -1,5 +1,5 @@ /* Sleep for a given number of seconds. POSIX.1 version. - Copyright (C) 1991-2014 Free Software Foundation, Inc. + Copyright (C) 1991-2015 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 @@ -33,7 +33,7 @@ unsigned int __sleep (unsigned int seconds) { /* This is not necessary but some buggy programs depend on it. */ - if (__builtin_expect (seconds == 0, 0)) + if (__glibc_unlikely (seconds == 0)) { #ifdef CANCELLATION_P CANCELLATION_P (THREAD_SELF); diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c index 58c9e5d597..eee9331ecf 100644 --- a/sysdeps/posix/spawni.c +++ b/sysdeps/posix/spawni.c @@ -1,5 +1,5 @@ /* Guts of POSIX spawn interface. Generic POSIX.1 version. - Copyright (C) 2000-2014 Free Software Foundation, Inc. + Copyright (C) 2000-2015 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 @@ -188,7 +188,7 @@ __spawni (pid_t *pid, const char *file, { if (! have_fdlimit) { - getrlimit64 (RLIMIT_NOFILE, &fdlimit); + __getrlimit64 (RLIMIT_NOFILE, &fdlimit); have_fdlimit = true; } diff --git a/sysdeps/posix/sprofil.c b/sysdeps/posix/sprofil.c index 0e19d16c23..abd59d5d0a 100644 --- a/sysdeps/posix/sprofil.c +++ b/sysdeps/posix/sprofil.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2014 Free Software Foundation, Inc. +/* Copyright (C) 2001-2015 Free Software Foundation, Inc. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>. This file is part of the GNU C Library. @@ -175,17 +175,17 @@ profil_count_uint (void *pcp) profil_count (pcp, 1); } -/* Get the machine-dependent definition of `profil_counter', the signal +/* Get the machine-dependent definition of `__profil_counter', the signal handler for SIGPROF. It calls `profil_count' (above) with the PC of the interrupted code. */ -#define profil_counter profil_counter_ushort +#define __profil_counter __profil_counter_ushort #define profil_count(pc) profil_count (pc, 0) #include <profil-counter.h> -#undef profil_counter +#undef __profil_counter #undef profil_count -#define profil_counter profil_counter_uint +#define __profil_counter __profil_counter_uint #define profil_count(pc) profil_count (pc, 1) #include <profil-counter.h> @@ -334,9 +334,9 @@ __sprofil (struct prof *profp, int profcnt, struct timeval *tvp, /* Install SIGPROF handler. */ if (flags & PROF_UINT) - act.sa_handler = (sighandler_t) &profil_counter_uint; + act.sa_handler = (sighandler_t) &__profil_counter_uint; else - act.sa_handler = (sighandler_t) &profil_counter_ushort; + act.sa_handler = (sighandler_t) &__profil_counter_ushort; act.sa_flags = SA_RESTART; __sigfillset (&act.sa_mask); if (__sigaction (SIGPROF, &act, &prof_info.saved_action) < 0) diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c index 26136bd9c9..502fe94909 100644 --- a/sysdeps/posix/sysconf.c +++ b/sysdeps/posix/sysconf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -31,6 +31,8 @@ #include <sys/types.h> #include <regex.h> +#define NEED_SPEC_ARRAY 0 +#include <posix-conf-vars.h> #define NEED_CHECK_SPEC \ (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \ @@ -95,112 +97,112 @@ __sysconf (name) return MAX (__tzname_max (), _POSIX_TZNAME_MAX); case _SC_JOB_CONTROL: -#if _POSIX_JOB_CONTROL > 0 +#if CONF_IS_DEFINED_SET (_POSIX_JOB_CONTROL) return _POSIX_JOB_CONTROL; #else return -1; #endif case _SC_SAVED_IDS: -#if _POSIX_SAVED_IDS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SAVED_IDS) return 1; #else return -1; #endif case _SC_REALTIME_SIGNALS: -#if _POSIX_REALTIME_SIGNALS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_REALTIME_SIGNALS) return _POSIX_REALTIME_SIGNALS; #else return -1; #endif case _SC_PRIORITY_SCHEDULING: -#if _POSIX_PRIORITY_SCHEDULING > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PRIORITY_SCHEDULING) return _POSIX_PRIORITY_SCHEDULING; #else return -1; #endif case _SC_TIMERS: -#if _POSIX_TIMERS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TIMERS) return _POSIX_TIMERS; #else return -1; #endif case _SC_ASYNCHRONOUS_IO: -#if _POSIX_ASYNCHRONOUS_IO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_ASYNCHRONOUS_IO) return _POSIX_ASYNCHRONOUS_IO; #else return -1; #endif case _SC_PRIORITIZED_IO: -#if _POSIX_PRIORITIZED_IO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PRIORITIZED_IO) return _POSIX_PRIORITIZED_IO; #else return -1; #endif case _SC_SYNCHRONIZED_IO: -#if _POSIX_SYNCHRONIZED_IO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SYNCHRONIZED_IO) return _POSIX_SYNCHRONIZED_IO; #else return -1; #endif case _SC_FSYNC: -#if _POSIX_FSYNC > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FSYNC) return _POSIX_FSYNC; #else return -1; #endif case _SC_MAPPED_FILES: -#if _POSIX_MAPPED_FILES > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MAPPED_FILES) return _POSIX_MAPPED_FILES; #else return -1; #endif case _SC_MEMLOCK: -#if _POSIX_MEMLOCK > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK) return _POSIX_MEMLOCK; #else return -1; #endif case _SC_MEMLOCK_RANGE: -#if _POSIX_MEMLOCK_RANGE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MEMLOCK_RANGE) return _POSIX_MEMLOCK_RANGE; #else return -1; #endif case _SC_MEMORY_PROTECTION: -#if _POSIX_MEMORY_PROTECTION > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MEMORY_PROTECTION) return _POSIX_MEMORY_PROTECTION; #else return -1; #endif case _SC_MESSAGE_PASSING: -#if _POSIX_MESSAGE_PASSING > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MESSAGE_PASSING) return _POSIX_MESSAGE_PASSING; #else return -1; #endif case _SC_SEMAPHORES: -#if _POSIX_SEMAPHORES > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SEMAPHORES) return _POSIX_SEMAPHORES; #else return -1; #endif case _SC_SHARED_MEMORY_OBJECTS: -#if _POSIX_SHARED_MEMORY_OBJECTS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SHARED_MEMORY_OBJECTS) return _POSIX_SHARED_MEMORY_OBJECTS; #else return -1; @@ -353,49 +355,49 @@ __sysconf (name) #endif case _SC_PII: -#if _POSIX_PII > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII) return 1; #else return -1; #endif case _SC_PII_XTI: -#if _POSIX_PII_XTI > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_XTI) return 1; #else return -1; #endif case _SC_PII_SOCKET: -#if _POSIX_PII_SOCKET > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_SOCKET) return 1; #else return -1; #endif case _SC_PII_INTERNET: -#if _POSIX_PII_INTERNET > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET) return 1; #else return -1; #endif case _SC_PII_OSI: -#if _POSIX_PII_OSI > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI) return 1; #else return -1; #endif case _SC_POLL: -#if _POSIX_POLL > 0 +#if CONF_IS_DEFINED_SET (_POSIX_POLL) return 1; #else return -1; #endif case _SC_SELECT: -#if _POSIX_SELECT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SELECT) return 1; #else return -1; @@ -410,35 +412,35 @@ __sysconf (name) #endif case _SC_PII_INTERNET_STREAM: -#if _POSIX_PII_INTERNET_STREAM > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_STREAM) return 1; #else return -1; #endif case _SC_PII_INTERNET_DGRAM: -#if _POSIX_PII_INTERNET_DGRAM > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_INTERNET_DGRAM) return 1; #else return -1; #endif case _SC_PII_OSI_COTS: -#if _POSIX_PII_OSI_COTS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_COTS) return 1; #else return -1; #endif case _SC_PII_OSI_CLTS: -#if _POSIX_PII_OSI_CLTS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_CLTS) return 1; #else return -1; #endif case _SC_PII_OSI_M: -#if _POSIX_PII_OSI_M > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PII_OSI_M) return 1; #else return -1; @@ -519,14 +521,14 @@ __sysconf (name) /* POSIX 1003.1c (POSIX Threads). */ case _SC_THREADS: -#if _POSIX_THREADS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREADS) return _POSIX_THREADS; #else return -1; #endif case _SC_THREAD_SAFE_FUNCTIONS: -#if _POSIX_THREAD_SAFE_FUNCTIONS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_SAFE_FUNCTIONS) return _POSIX_THREAD_SAFE_FUNCTIONS; #else return -1; @@ -553,7 +555,7 @@ __sysconf (name) #endif case _SC_THREAD_DESTRUCTOR_ITERATIONS: -#if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_DESTRUCTOR_ITERATIONS) return _POSIX_THREAD_DESTRUCTOR_ITERATIONS; #else return -1; @@ -581,42 +583,42 @@ __sysconf (name) #endif case _SC_THREAD_ATTR_STACKADDR: -#if _POSIX_THREAD_ATTR_STACKADDR > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKADDR) return _POSIX_THREAD_ATTR_STACKADDR; #else return -1; #endif case _SC_THREAD_ATTR_STACKSIZE: -#if _POSIX_THREAD_ATTR_STACKSIZE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_ATTR_STACKSIZE) return _POSIX_THREAD_ATTR_STACKSIZE; #else return -1; #endif case _SC_THREAD_PRIORITY_SCHEDULING: -#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIORITY_SCHEDULING) return _POSIX_THREAD_PRIORITY_SCHEDULING; #else return -1; #endif case _SC_THREAD_PRIO_INHERIT: -#if _POSIX_THREAD_PRIO_INHERIT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_INHERIT) return _POSIX_THREAD_PRIO_INHERIT; #else return -1; #endif case _SC_THREAD_PRIO_PROTECT: -#if _POSIX_THREAD_PRIO_PROTECT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PRIO_PROTECT) return _POSIX_THREAD_PRIO_PROTECT; #else return -1; #endif case _SC_THREAD_PROCESS_SHARED: -#if _POSIX_THREAD_PROCESS_SHARED > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_PROCESS_SHARED) return _POSIX_THREAD_PROCESS_SHARED; #else return -1; @@ -833,239 +835,237 @@ __sysconf (name) #endif case _SC_ADVISORY_INFO: -#if _POSIX_ADVISORY_INFO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_ADVISORY_INFO) return _POSIX_ADVISORY_INFO; #else return -1; #endif case _SC_BARRIERS: -#if _POSIX_BARRIERS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_BARRIERS) return _POSIX_BARRIERS; #else return -1; #endif case _SC_BASE: -#if _POSIX_BASE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_BASE) return _POSIX_BASE; #else return -1; #endif case _SC_C_LANG_SUPPORT: -#if _POSIX_C_LANG_SUPPORT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT) return _POSIX_C_LANG_SUPPORT; #else return -1; #endif case _SC_C_LANG_SUPPORT_R: -#if _POSIX_C_LANG_SUPPORT_R > 0 +#if CONF_IS_DEFINED_SET (_POSIX_C_LANG_SUPPORT_R) return _POSIX_C_LANG_SUPPORT_R; #else return -1; #endif case _SC_CLOCK_SELECTION: -#if _POSIX_CLOCK_SELECTION > 0 +#if CONF_IS_DEFINED_SET (_POSIX_CLOCK_SELECTION) return _POSIX_CLOCK_SELECTION; #else return -1; #endif case _SC_CPUTIME: -#if _POSIX_CPUTIME > 0 +#if CONF_IS_DEFINED_SET (_POSIX_CPUTIME) return _POSIX_CPUTIME; #else return -1; #endif case _SC_DEVICE_IO: -#if _POSIX_DEVICE_IO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_IO) return _POSIX_DEVICE_IO; #else return -1; #endif case _SC_DEVICE_SPECIFIC: -#if _POSIX_DEVICE_SPCIFIC > 0 +#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC) return _POSIX_DEVICE_SPECIFIC; #else return -1; #endif case _SC_DEVICE_SPECIFIC_R: -#if _POSIX_DEVICE_SPCIFIC_R > 0 +#if CONF_IS_DEFINED_SET (_POSIX_DEVICE_SPECIFIC_R) return _POSIX_DEVICE_SPECIFIC_R; #else return -1; #endif case _SC_FD_MGMT: -#if _POSIX_FD_MGMT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FD_MGMT) return _POSIX_FD_MGMT; #else return -1; #endif case _SC_FIFO: -#if _POSIX_FIFO > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FIFO) return _POSIX_FIFO; #else return -1; #endif case _SC_PIPE: -#if _POSIX_PIPE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_PIPE) return _POSIX_PIPE; #else return -1; #endif case _SC_FILE_ATTRIBUTES: -#if _POSIX_FILE_ATTRIBUTES > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FILE_ATTRIBUTES) return _POSIX_FILE_ATTRIBUTES; #else return -1; #endif case _SC_FILE_LOCKING: -#if _POSIX_FILE_LOCKING > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FILE_LOCKING) return _POSIX_FILE_LOCKING; #else return -1; #endif case _SC_FILE_SYSTEM: -#if _POSIX_FILE_SYSTEM > 0 +#if CONF_IS_DEFINED_SET (_POSIX_FILE_SYSTEM) return _POSIX_FILE_SYSTEM; #else return -1; #endif case _SC_MONOTONIC_CLOCK: -#if _POSIX_MONOTONIC_CLOCK +#if CONF_IS_DEFINED_SET (_POSIX_MONOTONIC_CLOCK) return _POSIX_MONOTONIC_CLOCK; #else return -1; #endif case _SC_MULTI_PROCESS: -#if _POSIX_MULTI_PROCESS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_MULTI_PROCESS) return _POSIX_MULTI_PROCESS; #else return -1; #endif case _SC_SINGLE_PROCESS: -#if _POSIX_SINGLE_PROCESS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SINGLE_PROCESS) return _POSIX_SINGLE_PROCESS; #else return -1; #endif case _SC_NETWORKING: -#if _POSIX_NETWORKING > 0 +#if CONF_IS_DEFINED_SET (_POSIX_NETWORKING) return _POSIX_NETWORKING; #else return -1; #endif case _SC_READER_WRITER_LOCKS: -#if _POSIX_READER_WRITER_LOCKS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_READER_WRITER_LOCKS) return _POSIX_READER_WRITER_LOCKS; #else return -1; #endif case _SC_SPIN_LOCKS: -#if _POSIX_SPIN_LOCKS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SPIN_LOCKS) return _POSIX_SPIN_LOCKS; #else return -1; #endif case _SC_REGEXP: -#if _POSIX_REGEXP > 0 +#if CONF_IS_DEFINED_SET (_POSIX_REGEXP) return _POSIX_REGEXP; #else return -1; #endif + /* _REGEX_VERSION has been removed with IEEE Std 1003.1-2001/Cor 2-2004, + item XSH/TC2/D6/137. */ case _SC_REGEX_VERSION: -#if _POSIX_REGEX_VERSION > 0 - return _POSIX_REGEX_VERSION; -#else return -1; -#endif case _SC_SHELL: -#if _POSIX_SHELL > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SHELL) return _POSIX_SHELL; #else return -1; #endif case _SC_SIGNALS: -#ifdef _POSUX_SIGNALS +#if CONF_IS_DEFINED (_POSIX_SIGNALS) return _POSIX_SIGNALS; #else return -1; #endif case _SC_SPAWN: -#if _POSIX_SPAWN > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SPAWN) return _POSIX_SPAWN; #else return -1; #endif case _SC_SPORADIC_SERVER: -#if _POSIX_SPORADIC_SERVER > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SPORADIC_SERVER) return _POSIX_SPORADIC_SERVER; #else return -1; #endif case _SC_THREAD_SPORADIC_SERVER: -#if _POSIX_THREAD_SPORADIC_SERVER > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_SPORADIC_SERVER) return _POSIX_THREAD_SPORADIC_SERVER; #else return -1; #endif case _SC_SYSTEM_DATABASE: -#if _POSIX_SYSTEM_DATABASE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE) return _POSIX_SYSTEM_DATABASE; #else return -1; #endif case _SC_SYSTEM_DATABASE_R: -#if _POSIX_SYSTEM_DATABASE_R > 0 +#if CONF_IS_DEFINED_SET (_POSIX_SYSTEM_DATABASE_R) return _POSIX_SYSTEM_DATABASE_R; #else return -1; #endif case _SC_THREAD_CPUTIME: -#if _POSIX_THREAD_CPUTIME > 0 +#if CONF_IS_DEFINED_SET (_POSIX_THREAD_CPUTIME) return _POSIX_THREAD_CPUTIME; #else return -1; #endif case _SC_TIMEOUTS: -#if _POSIX_TIMEOUTS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TIMEOUTS) return _POSIX_TIMEOUTS; #else return -1; #endif case _SC_TYPED_MEMORY_OBJECTS: -#if _POSIX_TYPED_MEMORY_OBJECTS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TYPED_MEMORY_OBJECTS) return _POSIX_TYPED_MEMORY_OBJECTS; #else return -1; #endif case _SC_USER_GROUPS: -#if _POSIX_USER_GROUPS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS) return _POSIX_USER_GROUPS; #else return -1; #endif case _SC_USER_GROUPS_R: -#if _POSIX_USER_GROUPS_R > 0 +#if CONF_IS_DEFINED_SET (_POSIX_USER_GROUPS_R) return _POSIX_USER_GROUPS_R; #else return -1; @@ -1130,25 +1130,25 @@ __sysconf (name) #endif case _SC_TRACE: -#if _POSIX_TRACE > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TRACE) return _POSIX_TRACE; #else return -1; #endif case _SC_TRACE_EVENT_FILTER: -#if _POSIX_TRACE_EVENT_FILTER > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TRACE_EVENT_FILTER) return _POSIX_TRACE_EVENT_FILTER; #else return -1; #endif case _SC_TRACE_INHERIT: -#if _POSIX_TRACE_INHERIT > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TRACE_INHERIT) return _POSIX_TRACE_INHERIT; #else return -1; #endif case _SC_TRACE_LOG: -#if _POSIX_TRACE_LOG > 0 +#if CONF_IS_DEFINED_SET (_POSIX_TRACE_LOG) return _POSIX_TRACE_LOG; #else return -1; @@ -1185,14 +1185,14 @@ __sysconf (name) return 0; case _SC_IPV6: -#if _POSIX_IPV6 > 0 +#if CONF_IS_DEFINED_SET (_POSIX_IPV6) return _POSIX_IPV6; #else return -1; #endif case _SC_RAW_SOCKETS: -#if _POSIX_RAW_SOCKETS > 0 +#if CONF_IS_DEFINED_SET (_POSIX_RAW_SOCKETS) return _POSIX_RAW_SOCKETS; #else return -1; diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c index e8b921febb..95b91abec4 100644 --- a/sysdeps/posix/system.c +++ b/sysdeps/posix/system.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/sysv_signal.c b/sysdeps/posix/sysv_signal.c index d2c9f1b81d..434a3e3176 100644 --- a/sysdeps/posix/sysv_signal.c +++ b/sysdeps/posix/sysv_signal.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/telldir.c b/sysdeps/posix/telldir.c index ed978545fe..91daddb0a2 100644 --- a/sysdeps/posix/telldir.c +++ b/sysdeps/posix/telldir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 1f86549df3..88dc0bf44a 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -15,8 +15,9 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#if HAVE_CONFIG_H +#if !_LIBC # include <config.h> +# include "tempname.h" #endif #include <sys/types.h> @@ -39,81 +40,41 @@ # define __GT_DIR 1 # define __GT_NOCREATE 2 #endif - -#if STDC_HEADERS || _LIBC -# include <stddef.h> -# include <stdlib.h> -# include <string.h> -#endif - -#if HAVE_FCNTL_H || _LIBC -# include <fcntl.h> -#endif - -#if HAVE_SYS_TIME_H || _LIBC -# include <sys/time.h> +#if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR \ + || GT_NOCREATE != __GT_NOCREATE) +# error report this to bug-gnulib@gnu.org #endif -#if HAVE_STDINT_H || _LIBC -# include <stdint.h> -#endif +#include <stddef.h> +#include <stdlib.h> +#include <string.h> -#if HAVE_UNISTD_H || _LIBC -# include <unistd.h> -#endif +#include <fcntl.h> +#include <sys/time.h> +#include <stdint.h> +#include <unistd.h> #include <sys/stat.h> -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif -#if !S_IRUSR && S_IREAD -# define S_IRUSR S_IREAD -#endif -#if !S_IRUSR -# define S_IRUSR 00400 -#endif -#if !S_IWUSR && S_IWRITE -# define S_IWUSR S_IWRITE -#endif -#if !S_IWUSR -# define S_IWUSR 00200 -#endif -#if !S_IXUSR && S_IEXEC -# define S_IXUSR S_IEXEC -#endif -#if !S_IXUSR -# define S_IXUSR 00100 -#endif #if _LIBC # define struct_stat64 struct stat64 +# define __secure_getenv __libc_secure_getenv #else # define struct_stat64 struct stat +# define __gen_tempname gen_tempname # define __getpid getpid # define __gettimeofday gettimeofday # define __mkdir mkdir # define __open open -# define __open64 open -# define __lxstat64(version, path, buf) lstat (path, buf) -# define __xstat64(version, path, buf) stat (path, buf) -#endif - -#if ! (HAVE_SECURE_GETENV || _LIBC) -# ifdef HAVE___SECURE_GETENV -# define __libc_secure_getenv __secure_getenv -# else -# define __libc_secure_getenv getenv -# endif +# define __lxstat64(version, file, buf) lstat (file, buf) +# define __secure_getenv secure_getenv #endif #ifdef _LIBC # include <hp-timing.h> # if HP_TIMING_AVAIL # define RANDOM_BITS(Var) \ - if (__builtin_expect (value == UINT64_C (0), 0)) \ + if (__glibc_unlikely (value == UINT64_C (0))) \ { \ /* If this is the first time this function is used initialize \ the variable we accumulate the value in to some somewhat \ @@ -137,6 +98,7 @@ # define uint64_t uintmax_t #endif +#if _LIBC /* Return nonzero if DIR is an existent directory. */ static int direxists (const char *dir) @@ -172,7 +134,7 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, if (try_tmpdir) { - d = __libc_secure_getenv ("TMPDIR"); + d = __secure_getenv ("TMPDIR"); if (d != NULL && direxists (d)) dir = d; else if (dir != NULL && direxists (dir)) @@ -207,8 +169,9 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx); return 0; } +#endif /* _LIBC */ -/* These are the characters used in temporary filenames. */ +/* These are the characters used in temporary file names. */ static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; @@ -240,7 +203,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) /* A lower bound on the number of temporary files to attempt to generate. The maximum total number of temporary file names that can exist for a given template is 62**6. It should never be - necessary to try all these combinations. Instead if a reasonable + necessary to try all of these combinations. Instead if a reasonable number of names is tried (we define reasonable as 62**3) fail to give the system administrator the chance to remove the problems. */ #define ATTEMPTS_MIN (62 * 62 * 62) @@ -267,15 +230,11 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) #ifdef RANDOM_BITS RANDOM_BITS (random_time_bits); #else -# if HAVE_GETTIMEOFDAY || _LIBC { struct timeval tv; __gettimeofday (&tv, NULL); random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; } -# else - random_time_bits = time (NULL); -# endif #endif value += random_time_bits ^ __getpid (); @@ -328,6 +287,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) default: assert (! "invalid KIND in __gen_tempname"); + abort (); } if (fd >= 0) diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c index 016c16ec82..52bc14acaf 100644 --- a/sysdeps/posix/time.c +++ b/sysdeps/posix/time.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/timespec_get.c b/sysdeps/posix/timespec_get.c index 05b24f30ae..2609b2e729 100644 --- a/sysdeps/posix/timespec_get.c +++ b/sysdeps/posix/timespec_get.c @@ -1,5 +1,5 @@ /* timespec_get -- C11 interface to sample a clock. Generic POSIX.1 version. - Copyright (C) 2013-2014 Free Software Foundation, Inc. + Copyright (C) 2013-2015 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 diff --git a/sysdeps/posix/truncate.c b/sysdeps/posix/truncate.c index 2473fbb8c9..0120459623 100644 --- a/sysdeps/posix/truncate.c +++ b/sysdeps/posix/truncate.c @@ -1,5 +1,5 @@ /* Truncate a file given by name. Generic POSIX.1 version. - Copyright (C) 1995-2014 Free Software Foundation, Inc. + Copyright (C) 1995-2015 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 diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c index 17ed3af867..e2f17ac394 100644 --- a/sysdeps/posix/ttyname.c +++ b/sysdeps/posix/ttyname.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/ttyname_r.c b/sysdeps/posix/ttyname_r.c index ffae375e36..483b78516e 100644 --- a/sysdeps/posix/ttyname_r.c +++ b/sysdeps/posix/ttyname_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/ulimit.c b/sysdeps/posix/ulimit.c index c9269ec874..d4a48cab58 100644 --- a/sysdeps/posix/ulimit.c +++ b/sysdeps/posix/ulimit.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/usleep.c b/sysdeps/posix/usleep.c new file mode 100644 index 0000000000..841f1fa1b1 --- /dev/null +++ b/sysdeps/posix/usleep.c @@ -0,0 +1,33 @@ +/* Implementation of the BSD usleep function using nanosleep. + Copyright (C) 1996-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <time.h> +#include <unistd.h> + +int +usleep (useconds_t useconds) +{ + struct timespec ts = { .tv_sec = (long int) (useconds / 1000000), + .tv_nsec = (long int) (useconds % 1000000) * 1000ul }; + + /* Note the usleep() is a cancellation point. But since we call + nanosleep() which itself is a cancellation point we do not have + to do anything here. */ + return __nanosleep (&ts, NULL); +} diff --git a/sysdeps/posix/utime.c b/sysdeps/posix/utime.c index a3140114a2..d618bf2814 100644 --- a/sysdeps/posix/utime.c +++ b/sysdeps/posix/utime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/utimes.c b/sysdeps/posix/utimes.c index cdfecfa397..bb6826baf1 100644 --- a/sysdeps/posix/utimes.c +++ b/sysdeps/posix/utimes.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2014 Free Software Foundation, Inc. +/* Copyright (C) 1995-2015 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 diff --git a/sysdeps/posix/wait.c b/sysdeps/posix/wait.c index 0a4965272f..5e52d19496 100644 --- a/sysdeps/posix/wait.c +++ b/sysdeps/posix/wait.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 diff --git a/sysdeps/posix/wait3.c b/sysdeps/posix/wait3.c index f87b4f14ab..faec545f75 100644 --- a/sysdeps/posix/wait3.c +++ b/sysdeps/posix/wait3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2014 Free Software Foundation, Inc. +/* Copyright (C) 1992-2015 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 diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c index a1f8cc8c4c..de41227916 100644 --- a/sysdeps/posix/waitid.c +++ b/sysdeps/posix/waitid.c @@ -1,5 +1,5 @@ /* Pseudo implementation of waitid. - Copyright (C) 1997-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1997. @@ -149,11 +149,7 @@ OUR_WAITID (idtype_t idtype, id_t id, siginfo_t *infop, int options) int -__waitid (idtype, id, infop, options) - idtype_t idtype; - id_t id; - siginfo_t *infop; - int options; +__waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) { if (SINGLE_THREAD_P) return do_waitid (idtype, id, infop, options); diff --git a/sysdeps/posix/writev.c b/sysdeps/posix/writev.c index ef0058e25e..f35c593c46 100644 --- a/sysdeps/posix/writev.c +++ b/sysdeps/posix/writev.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-2014 Free Software Foundation, Inc. +/* Copyright (C) 1991-2015 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 @@ -38,7 +38,7 @@ ifree (char **ptrp) Operates just like 'write' (see <unistd.h>) except that the data are taken from VECTOR instead of a contiguous buffer. */ ssize_t -__libc_writev (int fd, const struct iovec *vector, int count) +__writev (int fd, const struct iovec *vector, int count) { /* Find the total number of bytes to be written. */ size_t bytes = 0; @@ -88,7 +88,4 @@ __libc_writev (int fd, const struct iovec *vector, int count) return bytes_written; } -#ifndef __libc_writev -strong_alias (__libc_writev, __writev) -weak_alias (__libc_writev, writev) -#endif +weak_alias (__writev, writev) |