From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28692 invoked by alias); 23 Apr 2009 21:39:37 -0000 Received: (qmail 28669 invoked by uid 22791); 23 Apr 2009 21:39:37 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Apr 2009 21:39:25 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id n3NLloJv000532; Thu, 23 Apr 2009 23:47:50 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id n3NLlokO000531; Thu, 23 Apr 2009 23:47:50 +0200 Date: Thu, 23 Apr 2009 21:39:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix pwritev Message-ID: <20090423214749.GW16681@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00003.txt.bz2 Hi! sysdeps/posix/pwritev.c looks copied from preadv.c, with only half of the things changed that actually need changing. Fixed thusly, ok to commit? 2009-04-23 Jakub Jelinek * 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. --- libc/sysdeps/posix/pwritev.c.jj 2009-04-03 21:52:46.000000000 +0200 +++ libc/sysdeps/posix/pwritev.c 2009-04-23 23:10:52.000000000 +0200 @@ -44,12 +44,12 @@ ifree (char **ptrp) } -/* Read data from file descriptor FD at the given position OFFSET - without change the file pointer, 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 ) except that data are put in VECTOR instead - of a contiguous buffer. */ +/* 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 + position OFFSET without change the file pointer. The data is + written in the order specified. Operates just like 'write' (see + ) except that the data are taken from IOVEC instead of a + contiguous buffer. */ ssize_t PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset) { @@ -81,26 +81,14 @@ PWRITEV (int fd, const struct iovec *vec 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. */ - bytes = bytes_read; + char *ptr = buffer; for (int 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; - } + ptr = __mempcpy ((void *) ptr, (void *) vector[i].iov_base, + vector[i].iov_len); - return bytes_read; + /* Write the data. */ + return PWRITE (fd, buffer, bytes, offset); } #if __WORDSIZE == 64 && defined pwritev64 # undef pwritev64 --- libc/misc/sys/uio.h.jj 2009-04-07 07:56:51.000000000 +0200 +++ libc/misc/sys/uio.h 2009-04-23 23:13:20.000000000 +0200 @@ -58,7 +58,7 @@ extern ssize_t writev (int __fd, __const without change the file pointer, and put the result in the buffers described by IOVEC, which is a vector of COUNT 'struct iovec's. The buffers are filled in the order specified. Operates just like - 'read' (see ) except that data are put in IOVEC instead + 'pread' (see ) except that data are put in IOVEC instead of a contiguous buffer. This function is a cancellation point and therefore not marked with @@ -69,7 +69,7 @@ extern ssize_t preadv (int __fd, __const /* 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 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 ) except that the data are taken from IOVEC instead of a contiguous buffer. @@ -96,7 +96,7 @@ extern ssize_t __REDIRECT (pwritev, (int without change the file pointer, and put the result in the buffers described by IOVEC, which is a vector of COUNT 'struct iovec's. The buffers are filled in the order specified. Operates just like - 'read' (see ) except that data are put in IOVEC instead + 'pread' (see ) except that data are put in IOVEC instead of a contiguous buffer. This function is a cancellation point and therefore not marked with @@ -107,7 +107,7 @@ extern ssize_t preadv64 (int __fd, __con /* 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 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 ) except that the data are taken from IOVEC instead of a contiguous buffer. --- libc/misc/preadv64.c.jj 2009-04-03 21:52:00.000000000 +0200 +++ libc/misc/preadv64.c 2009-04-23 23:15:44.000000000 +0200 @@ -24,7 +24,7 @@ without change the file pointer, 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 ) except that data are put in VECTOR instead + 'pread' (see ) except that data are put in VECTOR instead of a contiguous buffer. */ ssize_t preadv64 (fd, vector, count, offset) --- libc/misc/preadv.c.jj 2009-04-03 21:51:53.000000000 +0200 +++ libc/misc/preadv.c 2009-04-23 23:15:37.000000000 +0200 @@ -24,7 +24,7 @@ without change the file pointer, 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 ) except that data are put in VECTOR instead + 'pread' (see ) except that data are put in VECTOR instead of a contiguous buffer. */ ssize_t preadv (fd, vector, count, offset) --- libc/misc/pwritev.c.jj 2009-04-03 21:52:10.000000000 +0200 +++ libc/misc/pwritev.c 2009-04-23 23:15:52.000000000 +0200 @@ -23,7 +23,7 @@ /* 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 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 ) except that the data are taken from VECTOR instead of a contiguous buffer. */ ssize_t --- libc/misc/pwritev64.c.jj 2009-04-03 21:52:16.000000000 +0200 +++ libc/misc/pwritev64.c 2009-04-23 23:16:01.000000000 +0200 @@ -23,7 +23,7 @@ /* 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 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 ) except that the data are taken from VECTOR instead of a contiguous buffer. */ ssize_t --- libc/sysdeps/posix/preadv.c.jj 2009-04-22 15:07:09.000000000 +0200 +++ libc/sysdeps/posix/preadv.c 2009-04-23 23:11:10.000000000 +0200 @@ -48,7 +48,7 @@ ifree (char **ptrp) without change the file pointer, 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 ) except that data are put in VECTOR instead + 'pread' (see ) except that data are put in VECTOR instead of a contiguous buffer. */ ssize_t PREADV (int fd, const struct iovec *vector, int count, OFF_T offset) Jakub