www.delorie.com/djgpp/doc/libc/libc_634.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]



#include <unistd.h>

int pwrite(int file, const void *buffer, size_t count, off_t offset);


This function writes count bytes from buffer to file at position offset. It returns the number of bytes actually written. It will return zero or a number less than count if the disk is full, and may return less than count even under valid conditions.

Note that if file is a text file, pwrite may write more bytes than it reports.

If count is zero, the function does nothing and returns zero. Use _write if you want to actually ask DOS to write zero bytes.

The precise behavior of pwrite when the target filesystem is full are somewhat troublesome, because DOS doesn't fail the underlying system call. If your application needs to rely on errno being set to ENOSPC in such cases, you need to invoke pwrite as shown in an example for write (see section write). In a nutshell, the trick is to call pwrite one more time after it returns a value smaller than the count parameter; then it will always set errno if the disk is full.

Return Value

The number of bytes written, zero at EOF, or -1 on error.


POSIX 1003.1-2001; not 1003.2-1992


const char buf[] = "abc";
const size_t bufsize = strlen(buf);

/* Write out buf, then overwrite 'b' with 'd'. NB: We should check
 * for errors. */
lseek(fd, 0L, SEEK_SET);
write(fd, buf, bufsize);
pwrite(fd, "d", 1, 1);

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004