Commit | Line | Data |
---|---|---|
0f4b110b KS |
1 | .TH FOPEN 3 4/8/79 3 |
2 | .SH NAME | |
3 | fopen, freopen \- open a stream | |
4 | .SH SYNOPSIS | |
5 | .B #include <nstdio.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 | .SH DESCRIPTION | |
23 | .I Fopen | |
24 | opens the file named by | |
25 | .I filename | |
26 | and associates a stream with it. | |
27 | .I Fopen | |
28 | returns a pointer to be used to identify | |
29 | the stream in subsequent operations. | |
30 | .PP | |
31 | .I Type | |
32 | is a character string having one of the following values: | |
33 | .TP 5 | |
34 | "r" | |
35 | open for reading | |
36 | .ns | |
37 | .TP 5 | |
38 | "w" | |
39 | create for writing | |
40 | .ns | |
41 | .TP 5 | |
42 | "rw" or "w+" | |
43 | Create for concurrent read/write access. | |
44 | The file is first truncated, if it exists, | |
45 | and created if it does not. | |
46 | .ns | |
47 | .TP 5 | |
48 | "a" | |
49 | Append: open for writing at end | |
50 | of file, or create for writing | |
51 | .ns | |
52 | .TP 5 | |
53 | "ra" or "a+" | |
54 | Read and append: open for concurrent read/write access at end | |
55 | of file, or create file and open with such access | |
56 | .ns | |
57 | .TP 5 | |
58 | "r+" | |
59 | Read and write: open for both reading and writing | |
60 | but do not truncate the file first. | |
61 | .PP | |
62 | .I Freopen | |
63 | substitutes the named file in place | |
64 | of the open | |
65 | .IR stream . | |
66 | It returns the original value of | |
67 | .IR stream . | |
68 | The original stream is closed. | |
69 | .PP | |
70 | .I Freopen | |
71 | is typically used to attach the preopened | |
72 | constant names, | |
73 | .B stdin, stdout, stderr, | |
74 | to specified files. | |
75 | .SH "SEE ALSO" | |
76 | open(2), | |
77 | fclose(3) | |
78 | .SH DIAGNOSTICS | |
79 | .I Fopen | |
80 | and | |
81 | .I freopen | |
82 | return the pointer | |
83 | .SM | |
84 | .B NULL | |
85 | if | |
86 | .I filename | |
87 | cannot be accessed. | |
88 | .SH BUGS | |
89 | The "+" syntax is included merely for compatibility with the USG | |
90 | stdio, and is not to be viewed as true support. | |
91 | The USG stdio has restrictions on how you can switch from reading | |
92 | to writing or vice versa. | |
93 | LibNS has no such restrictions, at a small runtime cost. |