mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-02 01:40:07 +00:00
6166815d69
2002-10-09 Ulrich Drepper <drepper@redhat.com> * Versions.def (libc): Add GLIBC_2.3.1. (libpthread): Add GLIBC_2.3.1. * include/signal.h: Add libc_hidden_proto for __sigwait, __sigwaitinfo, and __sigtimedwait. * signal/Versions: Add __sigtimedwait, __sigwait, and __sigwaitinfo. * sysdeps/unix/sysv/linux/sigtimedwait.c (__sigtimedwait): Add libc_hidden_def. * sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise. * sysdeps/unix/sysv/linux/sigwaitinfo.c (__sigwaitinfo): Likewise. * include/sys/msg.h: Declare __libc_msgrcv and __libc_msgsnd. * sysdeps/unix/sysv/linux/msgrcv.c (__msgrcv): Rename to __libc_msgrcv and make old name an alias. * sysdeps/unix/sysv/linux/msgsnd.c (__msgsnd): Rename to __libc_msgsnd and make old name an alias. * sysvipc/Versions (libc) [GLIBC_PRIVATE]: Add __libc_msgrcv and __libc_msgsnd. * include/sys/uio.h: Declare __libc_readv and __libc_writev. * misc/Versions (libc) [GLIBC_PRIVATE]: Add __libc_readv and __libc_writev. * sysdeps/generic/readv.c (__readv): Rename to __libc_readv and make old name an alias. * sysdeps/posix/readv.c: Likewise * sysdeps/unix/sysv/aix/readv.c: Likewise. * sysdeps/unix/sysv/linux/readv.c: Likewise. * sysdeps/generic/writev.c (__writev): Rename to __libc_writev and make old name an alias. * sysdeps/posix/writev.c: Likewise * sysdeps/unix/sysv/aix/writev.c: Likewise. * sysdeps/unix/sysv/linux/writev.c: Likewise. * include/sys/wait.h: Declare __waitid. * posix/Versions (libc) [GLIBC_PRIVATE]: Add __waitid. * sysdeps/generic/waitid.c (waitid): Rename to __waitid and make old name an alias. * sysdeps/posix/waitid.c: Likewise. * sysdeps/unix/sysv/aix/waitid.c: Likewise. * sysdeps/unix/sysv/linux/syscalls.list: Add creat syscall. 2002-10-07 Jakub Jelinek <jakub@redhat.com> * include/alloca.h (__libc_use_alloca, __libc_alloca_cutoff): New prototypes. (__MAX_ALLOCA_CUTOFF): Define. Include allocalim.h. * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r, _nss_dns_gethostbyaddr_r): Use alloca or malloc to allocate host_buffer depending on __libc_use_alloca. * resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r, _nss_dns_getnetbyaddr_r): Use alloca or malloc to allocate net_buffer depending on __libc_use_alloca. * resolv/res_query.c (res_nquery): Use alloca or malloc to allocate buf depending on __libc_use_alloca. * resolv/gethnamaddr.c (gethostbyname2, gethostbyaddr): Likewise. * stdio-common/vfprintf.c (vfprintf): Use __libc_use_alloca instead of hardcoded constants. Pass proper size argument to alloca and compute end for wide char version. * stdio-common/printf_fp.c (__printf_fp): Use __libc_use_alloca instead of hardcoded constants. * string/strcoll.c (strcoll): Likewise. * string/strxfrm.c (strxfrm): Likewise. * sysdeps/posix/readv.c (__readv): Likewise. * sysdeps/posix/writev.c (__writev): Likewise. * sysdeps/generic/allocalim.h: New file.
101 lines
2.9 KiB
C
101 lines
2.9 KiB
C
/* Copyright (C) 1991, 1992, 1996, 1997, 2002 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, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
#include <stdbool.h>
|
|
#include <sys/param.h>
|
|
#include <sys/uio.h>
|
|
|
|
/* Read data from file descriptor FD, and put the result in the
|
|
buffers described by VECTOR, which is a vector of COUNT `struct iovec's.
|
|
The buffers are filled in the order specified.
|
|
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)
|
|
{
|
|
char *buffer;
|
|
char *buffer_start;
|
|
size_t bytes;
|
|
ssize_t bytes_read;
|
|
int i;
|
|
bool use_malloc = false;
|
|
|
|
/* Find the total number of bytes to be read. */
|
|
bytes = 0;
|
|
for (i = 0; i < count; ++i)
|
|
{
|
|
/* Check for ssize_t overflow. */
|
|
if (SSIZE_MAX - bytes < vector[i].iov_len)
|
|
{
|
|
errno = EINVAL;
|
|
return -1;
|
|
}
|
|
bytes += vector[i].iov_len;
|
|
}
|
|
|
|
/* Allocate a temporary buffer to hold the data. We should normally
|
|
use alloca since it's faster and does not require synchronization
|
|
with other threads. But we cannot if the amount of memory
|
|
required is too large. */
|
|
if (__libc_use_alloca (bytes))
|
|
buffer = (char *) __alloca (bytes);
|
|
else
|
|
{
|
|
buffer = (char *) malloc (bytes);
|
|
if (buffer == NULL)
|
|
/* XXX I don't know whether it is acceptable to try reading
|
|
the data in chunks. Probably not so we just fail here. */
|
|
return -1;
|
|
|
|
use_malloc = true;
|
|
}
|
|
|
|
/* Read the data. */
|
|
bytes_read = __read (fd, buffer, bytes);
|
|
if (bytes_read <= 0)
|
|
return -1;
|
|
|
|
/* Copy the data from BUFFER into the memory specified by VECTOR. */
|
|
bytes = bytes_read;
|
|
buffer_start = buffer;
|
|
for (i = 0; i < count; ++i)
|
|
{
|
|
size_t copy = MIN (vector[i].iov_len, bytes);
|
|
|
|
(void) memcpy ((void *) vector[i].iov_base, (void *) buffer, copy);
|
|
|
|
buffer += copy;
|
|
bytes -= copy;
|
|
if (bytes == 0)
|
|
break;
|
|
}
|
|
|
|
if (use_malloc)
|
|
free (buffer_start);
|
|
|
|
return bytes_read;
|
|
}
|
|
#ifndef __libc_readv
|
|
strong_alias (__libc_readv, __readv)
|
|
weak_alias (__libc_readv, readv)
|
|
#endif
|