xref: /386bsd/usr/share/man/cat3/freopen.0 (revision a2142627)
1FOPEN(3)                  386BSD Programmer's Manual                  FOPEN(3)
2
3NNAAMMEE
4     ffooppeenn, ffddooppeenn, ffrreeooppeenn - stream open functions
5
6SSYYNNOOPPSSIISS
7     ##iinncclluuddee <<ssttddiioo..hh>>
8
9     _F_I_L_E *
10     ffooppeenn(_c_h_a_r *_p_a_t_h, _c_h_a_r *_m_o_d_e)
11
12     _F_I_L_E *
13     ffddooppeenn(_i_n_t _f_i_l_d_e_s, _c_h_a_r *_m_o_d_e)
14
15     _F_I_L_E *
16     ffrreeooppeenn(_c_h_a_r *_p_a_t_h, _c_h_a_r *_m_o_d_e, _F_I_L_E *_s_t_r_e_a_m)
17
18DDEESSCCRRIIPPTTIIOONN
19     The ffooppeenn() function opens the file whose name is the string pointed to
20     by _p_a_t_h and associates a stream with it.
21
22     The argument _m_o_d_e points to a string beginning with one of the following
23     sequences (Additional characters may follow these sequences.):
24
25     ``r''   Open text file for reading.  The stream is positioned at the
26             beginning of the file.
27
28     ``r+''  Open for reading and writing.  The stream is positioned at the
29             beginning of the file.
30
31     ``w''   Truncate file to zero length or create text file for writing.
32             The stream is positioned at the beginning of the file.  It ``w+''
33             Open for reading and writing.  The file is created if it does not
34             exist, otherwise it is truncated.  The stream is positioned at
35             the beginning of the file.
36
37     ``a''   Open for writing.  The file is created if it does not exist.  The
38             stream is positioned at the end of the file.
39
40     ``a+''  Open for reading and writing.  The file is created if it does not
41             exist.  The stream is positioned at the end of the file.
42
43     The _m_o_d_e string can also include the letter ``b'' either as a third
44     character or as a character between the characters in any of the two-
45     character strings described above.  This is strictly for compatibility
46     with ANSI C3.159-1989 (``ANSI C'') and has no effect; the ``b'' is
47     ignored.
48
49     Any created files will have mode "S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
50     S_IROTH | S_IWOTH" (0666), as modified by the process' umask value (see
51     umask(2)).
52
53     Reads and writes may be intermixed on read/write streams in any order,
54     and do not require an intermediate seek as in previous versions of _s_t_d_i_o.
55     This is not portable to other systems, however; ANSI C requires that a
56     file positioning function intervene between output and input, unless an
57     input operation encounters end-of-file.
58
59     The ffddooppeenn() function associates a stream with the existing file
60     descriptor, _f_i_l_d_e_s. The _m_o_d_e of the stream must be compatible with the
61     mode of the file descriptor.
62
63     The ffrreeooppeenn() function opens the file whose name is the string pointed to
64     by _p_a_t_h and associates the stream pointed to by _s_t_r_e_a_m with it.  The
65     original stream (if it exists) is closed.  The _m_o_d_e argument is used just
66     as in the fopen function.  The primary use of the ffrreeooppeenn() function is
67     to change the file associated with a standard text stream (_s_t_d_e_r_r, _s_t_d_i_n,
68     or _s_t_d_o_u_t).
69
70RREETTUURRNN VVAALLUUEESS
71     Upon successful completion ffooppeenn(), ffddooppeenn() and ffrreeooppeenn() return a FILE
72     pointer.  Otherwise, NULL is returned and the global variable _e_r_r_n_o is
73     set to indicate the error.
74
75EERRRROORRSS
76     [EINVAL]  The _m_o_d_e provided to ffooppeenn(), ffddooppeenn(), or ffrreeooppeenn() was
77               invalid.
78
79     The ffooppeenn(), ffddooppeenn() and ffrreeooppeenn() functions may also fail and set _e_r_r_n_o
80     for any of the errors specified for the routine malloc(3).
81
82     The ffooppeenn() function may also fail and set _e_r_r_n_o for any of the errors
83     specified for the routine open(2).
84
85     The ffddooppeenn() function may also fail and set _e_r_r_n_o for any of the errors
86     specified for the routine fcntl(2).
87
88     The ffrreeooppeenn() function may also fail and set _e_r_r_n_o for any of the errors
89     specified for the routines open(2),  fclose(3) and fflush(3).
90
91SSEEEE AALLSSOO
92     open(2),  fclose(3),  fseek(3),  funopen(3)
93
94SSTTAANNDDAARRDDSS
95     The ffooppeenn() and ffrreeooppeenn() functions conform to ANSI C3.159-1989 (``ANSI
96     C''). The ffddooppeenn() function conforms to IEEE Std1003.1-1988 (``POSIX'').
97
98BSD Experimental                 June 29, 1991                               2
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133