* sysdeps/unix/sysv/linux/preadv.c: The kernel API changed. Adjust.

* sysdeps/unix/sysv/linux/pwritev.c: Likewise.

2009-04-23  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/posix/pwritev.c (PWRITEV): Fix up comment.  Copy
	data from vector to temporary buffer and call PWRITEV after it
	instead of vice versa.
	* sysdeps/posix/preadv.c: Fix up comment.
	* misc/preadv.c: Likewise.
	* misc/preadv64.c: Likewise.
	* misc/pwritev.c: Likewise.
	* misc/pwritev64.c: Likewise.
	* misc/sys/uio.h (preadv, pwritev, preadv64, pwritev64): Likewise.

2009-04-23  Ulrich Drepper  <drepper@redhat.com>
This commit is contained in:
Ulrich Drepper 2009-04-23 22:52:24 +00:00
parent c7e74e5968
commit 7f8a28efb5
11 changed files with 55 additions and 41 deletions

View File

@ -1,3 +1,20 @@
2009-04-23 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/preadv.c: The kernel API changed. Adjust.
* sysdeps/unix/sysv/linux/pwritev.c: Likewise.
2009-04-23 Jakub Jelinek <jakub@redhat.com>
* sysdeps/posix/pwritev.c (PWRITEV): Fix up comment. Copy
data from vector to temporary buffer and call PWRITEV after it
instead of vice versa.
* sysdeps/posix/preadv.c: Fix up comment.
* misc/preadv.c: Likewise.
* misc/preadv64.c: Likewise.
* misc/pwritev.c: Likewise.
* misc/pwritev64.c: Likewise.
* misc/sys/uio.h (preadv, pwritev, preadv64, pwritev64): Likewise.
2009-04-23 Ulrich Drepper <drepper@redhat.com> 2009-04-23 Ulrich Drepper <drepper@redhat.com>
* shadow/sgetspent_r.c (__sgetspent_r): Recognize too small buffers. * shadow/sgetspent_r.c (__sgetspent_r): Recognize too small buffers.

View File

@ -58,7 +58,12 @@ __sgetsgent_r (const char *string, struct sgrp *resbuf, char *buffer,
{ {
char *sp; char *sp;
if (string < buffer || string >= buffer + buflen) if (string < buffer || string >= buffer + buflen)
sp = strncpy (buffer, string, buflen); {
buffer[buflen - 1] = '\0';
sp = strncpy (buffer, string, buflen);
if (buffer[buflen - 1] != '\0')
return ERANGE;
}
else else
sp = (char *) string; sp = (char *) string;

View File

@ -24,7 +24,7 @@
without change the file pointer, and put the result in the buffers without change the file pointer, and put the result in the buffers
described by VECTOR, which is a vector of COUNT 'struct iovec's. described by VECTOR, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified. Operates just like The buffers are filled in the order specified. Operates just like
'read' (see <unistd.h>) except that data are put in VECTOR instead 'pread' (see <unistd.h>) except that data are put in VECTOR instead
of a contiguous buffer. */ of a contiguous buffer. */
ssize_t ssize_t
preadv (fd, vector, count, offset) preadv (fd, vector, count, offset)

View File

@ -24,7 +24,7 @@
without change the file pointer, and put the result in the buffers without change the file pointer, and put the result in the buffers
described by VECTOR, which is a vector of COUNT 'struct iovec's. described by VECTOR, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified. Operates just like The buffers are filled in the order specified. Operates just like
'read' (see <unistd.h>) except that data are put in VECTOR instead 'pread' (see <unistd.h>) except that data are put in VECTOR instead
of a contiguous buffer. */ of a contiguous buffer. */
ssize_t ssize_t
preadv64 (fd, vector, count, offset) preadv64 (fd, vector, count, offset)

View File

@ -23,7 +23,7 @@
/* Write data pointed by the buffers described by VECTOR, which is a /* Write data pointed by the buffers described by VECTOR, which is a
vector of COUNT 'struct iovec's, to file descriptor FD at the given vector of COUNT 'struct iovec's, to file descriptor FD at the given
position OFFSET without change the file pointer. The data is position OFFSET without change the file pointer. The data is
written in the order specified. Operates just like 'write' (see written in the order specified. Operates just like 'pwrite' (see
<unistd.h>) except that the data are taken from VECTOR instead of a <unistd.h>) except that the data are taken from VECTOR instead of a
contiguous buffer. */ contiguous buffer. */
ssize_t ssize_t

View File

@ -23,7 +23,7 @@
/* Write data pointed by the buffers described by VECTOR, which is a /* Write data pointed by the buffers described by VECTOR, which is a
vector of COUNT 'struct iovec's, to file descriptor FD at the given vector of COUNT 'struct iovec's, to file descriptor FD at the given
position OFFSET without change the file pointer. The data is position OFFSET without change the file pointer. The data is
written in the order specified. Operates just like 'write' (see written in the order specified. Operates just like 'pwrite' (see
<unistd.h>) except that the data are taken from VECTOR instead of a <unistd.h>) except that the data are taken from VECTOR instead of a
contiguous buffer. */ contiguous buffer. */
ssize_t ssize_t

View File

@ -58,7 +58,7 @@ extern ssize_t writev (int __fd, __const struct iovec *__iovec, int __count)
without change the file pointer, and put the result in the buffers without change the file pointer, and put the result in the buffers
described by IOVEC, which is a vector of COUNT 'struct iovec's. described by IOVEC, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified. Operates just like The buffers are filled in the order specified. Operates just like
'read' (see <unistd.h>) except that data are put in IOVEC instead 'pread' (see <unistd.h>) except that data are put in IOVEC instead
of a contiguous buffer. of a contiguous buffer.
This function is a cancellation point and therefore not marked with This function is a cancellation point and therefore not marked with
@ -69,7 +69,7 @@ extern ssize_t preadv (int __fd, __const struct iovec *__iovec, int __count,
/* Write data pointed by the buffers described by IOVEC, which is a /* Write data pointed by the buffers described by IOVEC, which is a
vector of COUNT 'struct iovec's, to file descriptor FD at the given vector of COUNT 'struct iovec's, to file descriptor FD at the given
position OFFSET without change the file pointer. The data is position OFFSET without change the file pointer. The data is
written in the order specified. Operates just like 'write' (see written in the order specified. Operates just like 'pwrite' (see
<unistd.h>) except that the data are taken from IOVEC instead of a <unistd.h>) except that the data are taken from IOVEC instead of a
contiguous buffer. contiguous buffer.
@ -96,7 +96,7 @@ extern ssize_t __REDIRECT (pwritev, (int __fd, __const struct iovec *__iovec,
without change the file pointer, and put the result in the buffers without change the file pointer, and put the result in the buffers
described by IOVEC, which is a vector of COUNT 'struct iovec's. described by IOVEC, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified. Operates just like The buffers are filled in the order specified. Operates just like
'read' (see <unistd.h>) except that data are put in IOVEC instead 'pread' (see <unistd.h>) except that data are put in IOVEC instead
of a contiguous buffer. of a contiguous buffer.
This function is a cancellation point and therefore not marked with This function is a cancellation point and therefore not marked with
@ -107,7 +107,7 @@ extern ssize_t preadv64 (int __fd, __const struct iovec *__iovec, int __count,
/* Write data pointed by the buffers described by IOVEC, which is a /* Write data pointed by the buffers described by IOVEC, which is a
vector of COUNT 'struct iovec's, to file descriptor FD at the given vector of COUNT 'struct iovec's, to file descriptor FD at the given
position OFFSET without change the file pointer. The data is position OFFSET without change the file pointer. The data is
written in the order specified. Operates just like 'write' (see written in the order specified. Operates just like 'pwrite' (see
<unistd.h>) except that the data are taken from IOVEC instead of a <unistd.h>) except that the data are taken from IOVEC instead of a
contiguous buffer. contiguous buffer.

View File

@ -48,7 +48,7 @@ ifree (char **ptrp)
without change the file pointer, and put the result in the buffers without change the file pointer, and put the result in the buffers
described by VECTOR, which is a vector of COUNT 'struct iovec's. described by VECTOR, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified. Operates just like The buffers are filled in the order specified. Operates just like
'read' (see <unistd.h>) except that data are put in VECTOR instead 'pread' (see <unistd.h>) except that data are put in VECTOR instead
of a contiguous buffer. */ of a contiguous buffer. */
ssize_t ssize_t
PREADV (int fd, const struct iovec *vector, int count, OFF_T offset) PREADV (int fd, const struct iovec *vector, int count, OFF_T offset)

View File

@ -44,12 +44,12 @@ ifree (char **ptrp)
} }
/* Read data from file descriptor FD at the given position OFFSET /* Write data pointed by the buffers described by IOVEC, which is a
without change the file pointer, and put the result in the buffers vector of COUNT 'struct iovec's, to file descriptor FD at the given
described by VECTOR, which is a vector of COUNT 'struct iovec's. position OFFSET without change the file pointer. The data is
The buffers are filled in the order specified. Operates just like written in the order specified. Operates just like 'write' (see
'read' (see <unistd.h>) except that data are put in VECTOR instead <unistd.h>) except that the data are taken from IOVEC instead of a
of a contiguous buffer. */ contiguous buffer. */
ssize_t ssize_t
PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset) PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset)
{ {
@ -81,26 +81,14 @@ PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset)
return -1; return -1;
} }
/* Read the data. */
ssize_t bytes_read = PWRITE (fd, buffer, bytes, offset);
if (bytes_read <= 0)
return -1;
/* Copy the data from BUFFER into the memory specified by VECTOR. */ /* Copy the data from BUFFER into the memory specified by VECTOR. */
bytes = bytes_read; char *ptr = buffer;
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ ptr = __mempcpy ((void *) ptr, (void *) vector[i].iov_base,
size_t copy = MIN (vector[i].iov_len, bytes); vector[i].iov_len);
(void) memcpy ((void *) vector[i].iov_base, (void *) buffer, copy); /* Write the data. */
return PWRITE (fd, buffer, bytes, offset);
buffer += copy;
bytes -= copy;
if (bytes == 0)
break;
}
return bytes_read;
} }
#if __WORDSIZE == 64 && defined pwritev64 #if __WORDSIZE == 64 && defined pwritev64
# undef pwritev64 # undef pwritev64

View File

@ -37,6 +37,10 @@
# define OFF_T off_t # define OFF_T off_t
#endif #endif
#define LO_HI_LONG(val) \
(off_t) val, \
(off_t) ((((uint64_t) (val)) >> (sizeof (long) * 4)) >> (sizeof (long) * 4))
#ifndef __ASSUME_PREADV #ifndef __ASSUME_PREADV
static ssize_t PREADV_REPLACEMENT (int, __const struct iovec *, static ssize_t PREADV_REPLACEMENT (int, __const struct iovec *,
int, OFF_T) internal_function; int, OFF_T) internal_function;
@ -55,15 +59,13 @@ PREADV (fd, vector, count, offset)
if (SINGLE_THREAD_P) if (SINGLE_THREAD_P)
result = INLINE_SYSCALL (preadv, 5, fd, vector, count, result = INLINE_SYSCALL (preadv, 5, fd, vector, count,
(off_t) ((off64_t) offset >> 32), LO_HI_LONG (offset));
(off_t) (offset & 0xffffffff));
else else
{ {
int oldtype = LIBC_CANCEL_ASYNC (); int oldtype = LIBC_CANCEL_ASYNC ();
result = INLINE_SYSCALL (preadv, 5, fd, vector, count, result = INLINE_SYSCALL (preadv, 5, fd, vector, count,
(off_t) ((off64_t) offset >> 32), LO_HI_LONG (offset));
(off_t) (offset & 0xffffffff));
LIBC_CANCEL_RESET (oldtype); LIBC_CANCEL_RESET (oldtype);
} }

View File

@ -37,6 +37,10 @@
# define OFF_T off_t # define OFF_T off_t
#endif #endif
#define LO_HI_LONG(val) \
(off_t) val, \
(off_t) ((((uint64_t) (val)) >> (sizeof (long) * 4)) >> (sizeof (long) * 4))
#ifndef __ASSUME_PWRITEV #ifndef __ASSUME_PWRITEV
static ssize_t PWRITEV_REPLACEMENT (int, __const struct iovec *, static ssize_t PWRITEV_REPLACEMENT (int, __const struct iovec *,
int, OFF_T) internal_function; int, OFF_T) internal_function;
@ -55,15 +59,13 @@ PWRITEV (fd, vector, count, offset)
if (SINGLE_THREAD_P) if (SINGLE_THREAD_P)
result = INLINE_SYSCALL (pwritev, 5, fd, vector, count, result = INLINE_SYSCALL (pwritev, 5, fd, vector, count,
(off_t) ((off64_t) offset >> 32), LO_HI_LONG (offset));
(off_t) (offset & 0xffffffff));
else else
{ {
int oldtype = LIBC_CANCEL_ASYNC (); int oldtype = LIBC_CANCEL_ASYNC ();
result = INLINE_SYSCALL (pwritev, 5, fd, vector, count, result = INLINE_SYSCALL (pwritev, 5, fd, vector, count,
(off_t) ((off64_t) offset >> 32), LO_HI_LONG (offset));
(off_t) (offset & 0xffffffff));
LIBC_CANCEL_RESET (oldtype); LIBC_CANCEL_RESET (oldtype);
} }