| 1 | .TH FOPEN 3S |
| 2 | .SH NAME |
| 3 | fopen, freopen, fdopen \- open a stream |
| 4 | .SH SYNOPSIS |
| 5 | .B #include <stdio.h> |
| 6 | .PP |
| 7 | .SM |
| 8 | .B FILE |
| 9 | .B *fopen(filename, type) |
| 10 | .br |
| 11 | .B char *filename, *type; |
| 12 | .PP |
| 13 | .SM |
| 14 | .B FILE |
| 15 | .B *freopen(filename, type, stream) |
| 16 | .br |
| 17 | .B char *filename, *type; |
| 18 | .br |
| 19 | .SM |
| 20 | .B FILE |
| 21 | .B *stream; |
| 22 | .PP |
| 23 | .SM |
| 24 | .B FILE |
| 25 | .B *fdopen(fildes, type) |
| 26 | .br |
| 27 | .B char *type; |
| 28 | .SH DESCRIPTION |
| 29 | .I Fopen |
| 30 | opens the file named by |
| 31 | .I filename |
| 32 | and associates a stream with it. |
| 33 | .I Fopen |
| 34 | returns a pointer to be used to identify |
| 35 | the stream in subsequent operations. |
| 36 | .PP |
| 37 | .I Type |
| 38 | is a character string having one of the following values: |
| 39 | .TP 5 |
| 40 | "r" |
| 41 | open for reading |
| 42 | .ns |
| 43 | .TP 5 |
| 44 | "w" |
| 45 | create for writing |
| 46 | .ns |
| 47 | .TP 5 |
| 48 | "a" |
| 49 | append: open for writing at end |
| 50 | of file, or create for writing |
| 51 | .PP |
| 52 | .I Freopen |
| 53 | substitutes the named file in place |
| 54 | of the open |
| 55 | .IR stream . |
| 56 | It returns the original value of |
| 57 | .IR stream . |
| 58 | The original stream is closed. |
| 59 | .PP |
| 60 | .I Freopen |
| 61 | is typically used to attach the preopened |
| 62 | constant names, |
| 63 | .B stdin, stdout, stderr, |
| 64 | to specified files. |
| 65 | .PP |
| 66 | .I Fdopen |
| 67 | associates a stream with a file descriptor obtained from |
| 68 | .I open, dup, creat, |
| 69 | or |
| 70 | .IR pipe (2). |
| 71 | The |
| 72 | .I type |
| 73 | of the stream must agree with the mode of the open file. |
| 74 | .SH "SEE ALSO" |
| 75 | open(2), |
| 76 | fclose(3) |
| 77 | .SH DIAGNOSTICS |
| 78 | .I Fopen |
| 79 | and |
| 80 | .I freopen |
| 81 | return the pointer |
| 82 | .SM |
| 83 | .B NULL |
| 84 | if |
| 85 | .I filename |
| 86 | cannot be accessed. |
| 87 | .SH BUGS |
| 88 | .I Fdopen |
| 89 | is not portable to systems other than UNIX. |