PostgreSQL Source Code  git master
preadv.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "port/pg_iovec.h"
Include dependency graph for preadv.c:

Go to the source code of this file.

Functions

ssize_t pg_preadv (int fd, const struct iovec *iov, int iovcnt, off_t offset)
 

Function Documentation

◆ pg_preadv()

ssize_t pg_preadv ( int  fd,
const struct iovec iov,
int  iovcnt,
off_t  offset 
)

Definition at line 29 of file preadv.c.

30 {
31 #ifdef HAVE_READV
32  if (iovcnt == 1)
33  return pg_pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
34  if (lseek(fd, offset, SEEK_SET) < 0)
35  return -1;
36  return readv(fd, iov, iovcnt);
37 #else
38  ssize_t sum = 0;
39  ssize_t part;
40 
41  for (int i = 0; i < iovcnt; ++i)
42  {
43  part = pg_pread(fd, iov[i].iov_base, iov[i].iov_len, offset);
44  if (part < 0)
45  {
46  if (i == 0)
47  return -1;
48  else
49  return sum;
50  }
51  sum += part;
52  offset += part;
53  if (part < iov[i].iov_len)
54  return sum;
55  }
56  return sum;
57 #endif
58 }
int i
Definition: isn.c:73
ssize_t pg_pread(int fd, void *buf, size_t nbyte, off_t offset)
Definition: pread.c:27
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References fd(), i, and pg_pread().