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:
- Using the open64() function (see open64()--Open File (large file enabled)).
- Using the open() function (see open()--Open File) with O_LARGEFILE set in the oflag parameter.
For additional information about parameters, authorities, and error conditions, see pread()--Read from Descriptor with Offset.
Usage Notes
- 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.
- QFileSvr.400 File System Differences
When connecting to a system at release V5R4M5 and earlier, QFileSvr.400 does not support an offset greater than 2 GB minus 1 bytes. Otherwise, offset is limited by the file system being accessed on the server.
- All of the usage notes for pread() apply to pread64(). See Usage Notes in the pread API.
Example
The following example opens a file and reads input.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#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