Back to index

glibc  2.9
pwrite.c File Reference
#include <errno.h>
#include <unistd.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


ssize_t __libc_pwrite (int fd, const void *buf, size_t nbyte, off_t offset)

Function Documentation

ssize_t __libc_pwrite ( int  fd,
const void *  buf,
size_t  nbyte,
off_t  offset 

Definition at line 28 of file pwrite.c.

  /* Since we must not change the file pointer preserve the value so that
     we can restore it later.  */
  int save_errno;
  ssize_t result;
  off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
  if (old_offset == (off_t) -1)
    return -1;

  /* Set to wanted position.  */
  if (__libc_lseek (fd, offset, SEEK_SET) == (off_t) -1)
    return -1;

  /* Write out the data.  */
  result = __libc_write (fd, buf, nbyte);

  /* Now we have to restore the position.  If this fails we have to
     return this as an error.  But if the writing also failed we
     return this error.  */
  save_errno = errno;
  if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
      if (result == -1)
       __set_errno (save_errno);
      return -1;
  __set_errno (save_errno);

  return result;

Here is the call graph for this function: