[Linux manuál]
Návod, kniha: Linux Programmer's Manual
FILE *fopen(const char *path, const char
*mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode,
FILE *stream);
fopen, fdopen, freopen: funkce otevřeného proudu
Originální popis anglicky: fopen, fdopen, freopen - stream open functionsNávod, kniha: Linux Programmer's Manual
STRUČNĚ
#include <stdio.h>POPIS / INSTRUKCE
The fopen function opens the file whose name is the string pointed to by path and associates a stream with it. The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):- r
- Open text file for reading. The stream is positioned at the beginning of the file.
- r+
- Open for reading and writing. The stream is positioned at the beginning of the file.
- w
- Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
- w+
- Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
- a
- Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
- a+
- Open for reading and appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.
fseek(stream,0,SEEK_END);
call.
The fdopen function associates a stream with the existing file
descriptor, fildes. The mode of the stream (one of the values
"r", "r+", "w", "w+", "a",
"a+") must be compatible with the mode of the file descriptor. The
file position indicator of the new stream is set to that belonging to
fildes, and the error and end-of-file indicators are cleared. Modes
"w" or "w+" do not cause truncation of the file. The file
descriptor is not dup'ed, and will be closed when the stream created by
fdopen is closed. The result of applying fdopen to a shared
memory object is undefined.
The freopen function opens the file whose name is the string pointed to
by path and associates the stream pointed to by stream with it.
The original stream (if it exists) is closed. The mode argument is used
just as in the fopen function. The primary use of the freopen
function is to change the file associated with a standard text stream
(stderr, stdin, or stdout).
NÁVRATOVÁ HODNOTA
Upon successful completion fopen, fdopen and freopen return a FILE pointer. Otherwise, NULL is returned and the global variable errno is set to indicate the error.CHYBY / ERRORY
- EINVAL
- The mode provided to fopen, fdopen, or freopen was invalid.
ODPOVÍDAJÍCÍ
The fopen and freopen functions conform to ANSI X3.159-1989 (``ANSI C''). The fdopen function conforms to IEEE Std1003.1-1988 (``POSIX.1'').SOUVISEJÍCÍ
open(2), fclose(3), fileno(3)| 2002-01-03 | BSD MANPAGE |