FOPEN(3S) UNIX Programmer's Manual FOPEN(3S) NAME fopen, freopen, fdopen - open or re-open a stream file; con- vert file to stream SYNOPSIS #include FILE *fopen (file-name, type) char *file-name, *type; FILE *freopen (file-name, type, stream) char *file-name, *type; FILE *stream; FILE *fdopen (fildes, type) int fildes; char *type; HP-UX COMPATIBILITY Level: HP-UX/RUN ONLY Origin: System V 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 r+ open for update (reading and writing) w+ create for update a+ append; open or create for update at end of file _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, regardless of whether the open ulti- mately succeeds. _F_r_e_o_p_e_n is typically used to attach the preopened constant names stdin, stdout, and 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. When a file is opened for update, both input and output may be done on the resulting stream. However, output may not be directly followed by input without an intervening _f_s_e_e_k or _r_e_w_i_n_d, and input may not be directly followed by output without an intervening _f_s_e_e_k, _r_e_w_i_n_d, or an input operation which encounters end of file. When a file is opened for append (i. e., when /fItype is a or a+), it is impossible to overwrite information already in the file. _F_s_e_e_k may be used to reposition the file pointer to any position in the file, but when output is written to the file, the current file pointer is disregarded. All out- put is written at the end of the file and causes the file pointer to be repositioned at the end of the output. If two separate processes open the same file for append, each pro- cess may write freely to the file without fear of destroying output being written by the other. The output from the two processes will be intermixed in the file in the order which it is written. SEE ALSO creat(2), dup(2), open(2), pipe(2), fclose(3S), fseek(3s), popen(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 can- not be accessed, if there are too many open files, or if the arguments are incorrect. _F_d_o_p_e_n returns a NULL if there are too many open files, or if the arguments are ill-formed.