pread64()--Read from Descriptor with Offset (large file enabled)


  Syntax
 #include <unistd.h>

 ssize_t pread64(int file_descriptor,
             void *buf, size_t nbyte, off64_t offset);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

From the file indicated by file_descriptor, the pread64() function reads nbyte bytes of input into the memory area indicated by buf. The offset value defines the starting position in the file and the file pointer position is not changed.

pread64() is enabled for large files. It is capable of operating on files larger than 2GB minus 1 byte as long as the file has been opened by either of the following:

For additional information about parameters, authorities, and error conditions, see pread()--Read from Descriptor with Offset.


Usage Notes

  1. When you develop in C-based languages, the prototypes for the 64-bit APIs are normally hidden. To use the pread64 API, you must compile the source with the _LARGE_FILE_API macro defined.
  2. All of the usage notes for pread() apply to pread64(). See Usage Notes in the pread API.

Example

See Code disclaimer information for information pertaining to code examples.

The following example opens a file and reads input:

#define _LARGE_FILE_API
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

main() {
  int ret, file_descriptor;
  off64_t  off=5;
  char buf[]="Test text";

  if ((file_descriptor = creat64("test.output", S_IWUSR))!= 0)
     perror("creat64() error");
  else {
    if (-1==(rc=write(file_descriptor, buf, sizof(buf)-1)))
       perror("write() error");
    if (close(file_descriptor)!= 0)
       perror("close() error");
  }

  if ((file_descriptor = open64("test.output", O_RDONLY)) < 0)
    perror("open64() error");
  else {
    ret = pread64(file_descriptor, buf, ((sizeof(buf)-1)-off), off);
    buf[ret] = 0x00;
    printf("block pread64: \n<%s>\n", buf);
    if (close(file_descriptor)!= 0)
       perror("close() error");
  }
  if (unlink("test.output")!= 0)
     perror("unlink() error");
}

Output:

block pread64:
<text>


API introduced: V5R2
Top | UNIX-Type APIs | APIs by category