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

Go to the source code of this file.

Functions

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

Function Documentation

◆ pg_pwrite()

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

Definition at line 27 of file pwrite.c.

References _dosmaperr(), and write.

Referenced by FileWrite(), XLogFileInit(), and XLogWrite().

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 (!WriteFile(handle, buf, size, &result, &overlapped))
43  {
44  _dosmaperr(GetLastError());
45  return -1;
46  }
47 
48  return result;
49 #else
50  if (lseek(fd, offset, SEEK_SET) < 0)
51  return -1;
52 
53  return write(fd, buf, size);
54 #endif
55 }
#define write(a, b, c)
Definition: win32.h:14
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