FSEEK(3s,L) AIX Technical Reference FSEEK(3s,L) ------------------------------------------------------------------------------- fseek, rewind, ftell PURPOSE Repositions the file pointer of a stream. LIBRARY Standard I/O Library (libc.a) SYNTAX #include int fseek (stream, offset, whence) void rewind (stream) FILE *stream; FILE *stream; long offset; int whence; long ftell (stream) FILE *stream; DESCRIPTION The fseek subroutine sets the position of the next input or output operation on the I/O stream specified by the stream parameter. The position of the next operation is determined by the offset parameter, which can be either positive or negative. The fseek subroutine sets the file pointer associated with the specified stream as follows: o If the whence parameter is 0, the pointer is set to the value of the offset parameter. o If the whence parameter is 1, the pointer is set to its current location plus the value of the offset parameter. o If the whence parameter is 2, the pointer is set to the size of the file plus the value of the offset parameter. The fseek subroutine fails if attempted on a file that has not been opened using fopen. In particular, fseek cannot be used on a terminal, or on a file opened with popen. Upon successful completion, fseek returns a value of 0. If fseek fails, a nonzero value is returned. Processed July 12, 1991 FSEEK(3s,L) 1 FSEEK(3s,L) AIX Technical Reference FSEEK(3s,L) The rewind subroutine is equivalent to fseek (stream, (long) 0, 0), except that it does not return a value. The fseek and rewind subroutines undo any effects of the ungetc subroutine. After an fseek or a rewind, the next operation on a file opened for update can be either input or output. The ftell subroutine returns the offset of the current byte relative to the beginning of the file associated with the named stream. ERROR CONDITIONS The fseek subroutine fails if the following is true: EINVAL The resulting file-position indicator is set to a negative value. The fseek and ftell subroutines fail if the following are true: EBADF The stream had data to be flushed but the underlying file is not open for writing. EFBIG An attempt was made to write a file that exceeds the process's file size limit or the maximum file size. EINVAL The whence argument is invalid. ENOSPC There was no free space remaining on the device containing the file. ESPIPE The file descriptor underlying stream is associated with a pipe or FIFO. EAGAIN The O_NONBLOCK flag is set for the file descriptor and the process would be delayed in the write operation. EINTR The write operation was terminated due to the receipt of a signal and no data was transferred. EIO An I/O error occurred. EPIPE An attempt was made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal will also be sent to the process. RELATED INFORMATION In this book: "fopen, freopen, fdopen," "lseek," and "stdio." Processed July 12, 1991 FSEEK(3s,L) 2