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

Go to the source code of this file.

Functions

ssize_t pg_pread (int fd, void *buf, size_t size, off_t offset)
 

Function Documentation

◆ pg_pread()

ssize_t pg_pread ( int  fd,
void *  buf,
size_t  size,
off_t  offset 
)

Definition at line 27 of file pread.c.

References _dosmaperr(), and read.

Referenced by basebackup_read_file(), FileRead(), WALRead(), and XLogPageRead().

28 {
29 #ifdef WIN32
30  OVERLAPPED overlapped = {0};
31  HANDLE handle;
32  DWORD result;
33 
34  handle = (HANDLE) _get_osfhandle(fd);
35  if (handle == INVALID_HANDLE_VALUE)
36  {
37  errno = EBADF;
38  return -1;
39  }
40 
41  overlapped.Offset = offset;
42  if (!ReadFile(handle, buf, size, &result, &overlapped))
43  {
44  if (GetLastError() == ERROR_HANDLE_EOF)
45  return 0;
46 
47  _dosmaperr(GetLastError());
48  return -1;
49  }
50 
51  return result;
52 #else
53  if (lseek(fd, offset, SEEK_SET) < 0)
54  return -1;
55 
56  return read(fd, buf, size);
57 #endif
58 }
void _dosmaperr(unsigned long)
Definition: win32error.c:171
static int fd(const char *x, int i)
Definition: preproc-init.c:105
static char * buf
Definition: pg_test_fsync.c:67
#define read(a, b, c)
Definition: win32.h:13