|
|
#include <stdio.h>FILE *fopen (filename, type) const char *filename, *type;
FILE *freopen (filename, type, stream) const char *filename, *type; FILE *stream;
FILE *fdopen (fildes, type) int fildes; const char *type;
filename points to a character string that contains the name of the file to be opened.
type is a character string with one of the following values:
freopen substitutes the named file in place of the open stream. The original stream is closed, regardless of whether the open succeeds. freopen returns a pointer to the FILE structure associated with stream.
freopen is typically used to attach the preopened streams associated with stdin, stdout, and stderr to other files.
fdopen associates a stream with a file descriptor. File descriptors are obtained from open(S-osr5), dup(S-osr5), creat(S-osr5), or pipe(S-osr5), which open files but do not return pointers to a FILE structure stream. Streams are necessary input for many library routines. The type of stream must agree with the mode of the open file. See Warning below.
When a file is opened for update, both input and output can be done on the resulting stream. However, output cannot be directly followed by input without an intervening fseek or rewind, and input cannot be directly followed by output without an intervening fseek, rewind, or input operation that encounters end-of-file.
When a file is opened for append (that is, when type is "a" or "a+"), it is impossible to overwrite information already in the file. The fseek function can be used to reposition the file pointer to any position in the file. However, when output is written to the file, the current file pointer is disregarded. All output is written at the end of the file and causes the file pointer to be repositioned at the end of the output. If two separate processes open the same file for append, each process can write to the file without destroying output written by the other. The output from the two processes is intermixed in the file in the order in which it is written.
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.
fopen and freopen are conformant with:
X/Open Portability Guide, Issue 3, 1989
;
ANSI X3.159-1989 Programming Language -- C
;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2)
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.