Consistently use "superuser" instead of "super user"
[pgsql.git] / src / port / pwritev.c
blob2e8ef7e3785a11c451627d0f78e2a18beefbd1dd
1 /*-------------------------------------------------------------------------
3 * pwritev.c
4 * Implementation of pwritev(2) for platforms that lack one.
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8 * IDENTIFICATION
9 * src/port/pwritev.c
11 * Note that this implementation changes the current file position, unlike
12 * the POSIX-like function, so we use the name pg_pwritev().
14 *-------------------------------------------------------------------------
18 #include "postgres.h"
20 #ifdef WIN32
21 #include <windows.h>
22 #else
23 #include <unistd.h>
24 #endif
26 #include "port/pg_iovec.h"
28 ssize_t
29 pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
31 #ifdef HAVE_WRITEV
32 if (iovcnt == 1)
33 return pg_pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
34 if (lseek(fd, offset, SEEK_SET) < 0)
35 return -1;
36 return writev(fd, iov, iovcnt);
37 #else
38 ssize_t sum = 0;
39 ssize_t part;
41 for (int i = 0; i < iovcnt; ++i)
43 part = pg_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
44 if (part < 0)
46 if (i == 0)
47 return -1;
48 else
49 return sum;
51 sum += part;
52 offset += part;
53 if (part < iov[i].iov_len)
54 return sum;
56 return sum;
57 #endif