diff options
Diffstat (limited to 'sysdeps/posix')
-rw-r--r-- | sysdeps/posix/getaddrinfo.c | 37 | ||||
-rw-r--r-- | sysdeps/posix/opendir.c | 1 | ||||
-rw-r--r-- | sysdeps/posix/timespec_get.c | 38 | ||||
-rw-r--r-- | sysdeps/posix/truncate.c | 17 |
4 files changed, 82 insertions, 11 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index d95c2d1156..7bb3ded9af 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -47,6 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdio_ext.h> #include <stdlib.h> #include <string.h> +#include <stdint.h> #include <arpa/inet.h> #include <net/if.h> #include <netinet/in.h> @@ -1035,7 +1036,15 @@ gaih_inet (const char *name, const struct gaih_service *service, } } else - status = NSS_STATUS_UNAVAIL; + { + status = NSS_STATUS_UNAVAIL; + /* Could not load any of the lookup functions. Indicate + an internal error if the failure was due to a system + error other than the file not being found. We use the + errno from the last failed callback. */ + if (errno != 0 && errno != ENOENT) + __set_h_errno (NETDB_INTERNAL); + } } if (nss_next_action (nip, status) == NSS_ACTION_RETURN) @@ -1049,7 +1058,7 @@ gaih_inet (const char *name, const struct gaih_service *service, _res.options |= old_res_options & RES_USE_INET6; - if (status == NSS_STATUS_UNAVAIL) + if (h_errno == NETDB_INTERNAL) { result = GAIH_OKIFUNSPEC | -EAI_SYSTEM; goto free_and_return; @@ -2489,11 +2498,28 @@ getaddrinfo (const char *name, const char *service, __typeof (once) old_once = once; __libc_once (once, gaiconf_init); /* Sort results according to RFC 3484. */ - struct sort_result results[nresults]; - size_t order[nresults]; + struct sort_result *results; + size_t *order; struct addrinfo *q; struct addrinfo *last = NULL; char *canonname = NULL; + bool malloc_results; + size_t alloc_size = nresults * (sizeof (*results) + sizeof (size_t)); + + malloc_results + = !__libc_use_alloca (alloc_size); + if (malloc_results) + { + results = malloc (alloc_size); + if (results == NULL) + { + __free_in6ai (in6ai); + return EAI_MEMORY; + } + } + else + results = alloca (alloc_size); + order = (size_t *) (results + nresults); /* Now we definitely need the interface information. */ if (! check_pf_called) @@ -2664,6 +2690,9 @@ getaddrinfo (const char *name, const char *service, /* Fill in the canonical name into the new first entry. */ p->ai_canonname = canonname; + + if (malloc_results) + free (results); } __free_in6ai (in6ai); diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c index 0efeb5d30d..ddfc3a7510 100644 --- a/sysdeps/posix/opendir.c +++ b/sysdeps/posix/opendir.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <dirent.h> #include <fcntl.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> diff --git a/sysdeps/posix/timespec_get.c b/sysdeps/posix/timespec_get.c new file mode 100644 index 0000000000..a578e8b986 --- /dev/null +++ b/sysdeps/posix/timespec_get.c @@ -0,0 +1,38 @@ +/* timespec_get -- C11 interface to sample a clock. Generic POSIX.1 version. + Copyright (C) 2013 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. + + 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> + + +/* Set TS to calendar time based in time base BASE. */ +int +timespec_get (struct timespec *ts, int base) +{ + switch (base) + { + case TIME_UTC: + if (__clock_gettime (CLOCK_REALTIME, ts) < 0) + return 0; + break; + + default: + return 0; + } + + return base; +} diff --git a/sysdeps/posix/truncate.c b/sysdeps/posix/truncate.c index ae29be8106..7ef1400eb5 100644 --- a/sysdeps/posix/truncate.c +++ b/sysdeps/posix/truncate.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1995-2013 Free Software Foundation, Inc. +/* Truncate a file given by name. Generic POSIX.1 version. + Copyright (C) 1995-2013 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -22,20 +23,22 @@ /* Truncate PATH to LENGTH bytes. */ int -truncate (path, length) - const char *path; - off_t length; +__truncate (const char *path, off_t length) { int fd, ret, save; - fd = open (path, O_WRONLY); + fd = __open (path, O_WRONLY | (length == 0 ? O_TRUNC : 0)); if (fd < 0) return -1; - ret = ftruncate (fd, length); + if (length == 0) + ret = 0; + else + ret = __ftruncate (fd, length); save = errno; - (void) close (fd); + (void) __close (fd); if (ret < 0) __set_errno (save); return ret; } +weak_alias (__truncate, truncate) |