FOPEN(3S) UNIX Programmer's Manual FOPEN(3S) NAME fopen, freopen, fdopen - open a stream SYNOPSIS #include FILE *fopen(filename, type) char *filename, *type; FILE *freopen(filename, type, stream) char *filename, *type; FILE *stream; FILE *fdopen(fildes, type) char *type; DESCRIPTION _F_o_p_e_n opens the file named by _f_i_l_e_n_a_m_e and associates a stream with it. _F_o_p_e_n returns a pointer to be used to iden- tify the stream in subsequent operations. _T_y_p_e is a character string having one of the following values: "r" open for reading "w" create for writing "a" append: open for writing at end of file, or create for writing In addition, each _t_y_p_e may be followed by a '+' to have the file opened for reading and writing. "r+" positions the stream at the beginning of the file, "w+" creates or trun- cates it, and "a+" positions it at the end. Both reads and writes may be used on read/write streams, with the limita- tion that an _f_s_e_e_k, _r_e_w_i_n_d, or reading an end-of-file must be used between a read and a write or vice-versa. _F_r_e_o_p_e_n substitutes the named file in place of the open _s_t_r_e_a_m. It returns the original value of _s_t_r_e_a_m. The ori- ginal stream is closed. _F_r_e_o_p_e_n is typically used to attach the preopened constant names, stdin, stdout, stderr, to specified files. _F_d_o_p_e_n associates a stream with a file descriptor obtained from _o_p_e_n, _d_u_p, _c_r_e_a_t, or _p_i_p_e(2). The _t_y_p_e of the stream must agree with the mode of the open file. SEE ALSO open(2), fclose(3S) Printed 7/31/83 1 FOPEN(3S) UNIX Programmer's Manual FOPEN(3S) DIAGNOSTICS _F_o_p_e_n and _f_r_e_o_p_e_n return the pointer NULL if _f_i_l_e_n_a_m_e cannot be accessed. BUGS _F_d_o_p_e_n is not portable to systems other than UNIX. The read/write _t_y_p_es do not exist on all systems. Those systems without read/write modes will probably treat the _t_y_p_e as if the '+' was not present. Printed 7/31/83 2