#include <stdio.h>
FILE *fopen ( Path, Type)
const char *Path, *Type;
FILE *fopen64 ( Path, Type)
char *Path, *Type;
FILE *freopen (Path, Type, Stream)
const char *Path, *Type;
FILE *Stream;
FILE *freopen64 (Path, Type, Stream)
char *Path, *Type;
FILE *Stream;
FILE *fdopen ( FileDescriptor, Type)
int FileDescriptor;
const char *Type;
The fopen and fopen64 subroutines open the file named by the Path parameter and associate a stream with it and return a pointer to the FILE structure of this stream.
When you open a file for update, you can perform both input and output operations on the resulting stream. However, an output operation cannot be directly followed by an input operation without an intervening fflush subroutine call or a file positioning operation (fseek, fseeko, fseeko64, fsetpos, fsetpos64 or rewind subroutine). Also, an input operation cannot be directly followed by an output operation without an intervening flush or file positioning operation, unless the input operation encounters the end of the file.
When you open a file for appending (that is, when the Type parameter is set to a), it is impossible to overwrite information already in the file.
If two separate processes open the same file for append, each process can write freely to the file without destroying the output being written by the other. The output from the two processes is intermixed in the order in which it is written to the file.
Note: If the data is buffered, it is not actually written until it is flushed.
The freopen and freopen64 subroutines first attempt to flush the stream and close any file descriptor associated with the Stream parameter. Failure to flush the stream or close the file descriptor is ignored.
The freopen and freopen64 subroutines substitute the named file in place of the open stream. The original stream is closed regardless of whether the subsequent open succeeds. The freopen and freopen64 subroutines returns a pointer to the FILE structure associated with the Stream parameter. The freopen and freopen64 subroutines is typically used to attach the pre-opened streams associated with standard input (stdin), standard output (stdout), and standard error (stderr) streams to other files.
The fdopen subroutine associates a stream with a file descriptor obtained from an openx subroutine, dup subroutine, creat subroutine, or pipe subroutine. These subroutines open files but do not return pointers to FILE structures. Many of the standard I/O package subroutines require pointers to FILE structures.
The Type parameter for the fdopen subroutine specifies the mode of the stream, such as r to open a file for reading, or a to open a file for appending (writing at the end of the file). The mode value of the Type parameter specified with the fdopen subroutine must agree with the mode of the file specified when the file was originally opened or created.
The largest value that can be represented correctly in an object of type off_t will be established as the offset maximum in the open file description.
If the fdopen, fopen, fopen64, freopen or freopen64 subroutine is unsuccessful, a null pointer is returned and the errno global variable is set to indicate the error.
The fopen,
fopen64, freopen and freopen64 subroutines
are unsuccessful if the following is true:
The fdopen,
fopen, fopen64, freopen and
freopen64 subroutines are unsuccessful if the following is
true:
The freopen and
fopen subroutines are unsuccessful if the following is true:
EOVERFLOW | The named file is a size larger than 2 Gigabytes. |
The fdopen subroutine is
unsuccessful if the following is true:
EBADF | The value of the File Descriptor parameter is not valid. |
These subroutines are part of Base Operating System (BOS) Runtime.
At least eight streams, including three standard text streams, can open simultaneously. Both binary and text modes are supported.
The fclose or fflush (fclose or fflush Subroutine) subroutine, fseek, fseeko, fseeko64, rewind, ftell, ftello, ftello64, fgetpos, fgetpos64 or fsetpos (fseek, fseeko, fseeko64, rewind, ftell, ftello, ftello64, fgetpos, fgetpos64, fsetpos, or fsetpos64 Subroutine) subroutine, open, open64, openx, or creat (open, openx, open64, creat, or creat64 Subroutine) subroutine, setbuf, setvbuf, setbuffer, or setlinebuf subroutine.
The Input and Output Handling in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.