FOPEN(3) BSD Programmer's Manual FOPEN(3) NNAAMMEE ffooppeenn, ffddooppeenn, ffrreeooppeenn - stream open functions SSYYNNOOPPSSIISS ##iinncclluuddee <> _F_I_L_E _* ffooppeenn(_c_h_a_r _*_p_a_t_h, _c_h_a_r _*_m_o_d_e); _F_I_L_E _* ffddooppeenn(_i_n_t _f_i_l_d_e_s, _c_h_a_r _*_m_o_d_e); _F_I_L_E _* 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); DDEESSCCRRIIPPTTIIOONN The ffooppeenn() function opens the file whose name is the string pointed to by _p_a_t_h and associates a stream with it. The argument _m_o_d_e points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): ``r'' Open text file for reading. The stream is positioned at the be- ginning of the file. ``r+'' Open for reading and writing. The stream is positioned at the beginning of the file. ``w'' Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. It ``w+'' Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. ``a'' Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. ``a+'' Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. The _m_o_d_e string can also include the letter ``b'' either as a third char- acter or as a character between the characters in any of the two- character strings described above. This is strictly for compatibility with ANSI C X3.159-1989 (``ANSI C '') and has no effect; the ``b'' is ig- nored. Any created files will have mode "S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH" (0666), as modified by the process' umask value (see umask(2)). Reads and writes may be intermixed on read/write streams in any order, and do not require an intermediate seek as in previous versions of _s_t_d_i_o. This is not portable to other systems, however; ANSI C requires that a file positioning function intervene between output and input, unless an input operation encounters end-of-file. The ffddooppeenn() function associates a stream with the existing file descrip- tor, _f_i_l_d_e_s. The _m_o_d_e of the stream must be compatible with the mode of the file descriptor. The ffrreeooppeenn() function opens the file whose name is the string pointed to by _p_a_t_h and associates the stream pointed to by _s_t_r_e_a_m with it. The original stream (if it exists) is closed. The _m_o_d_e argument is used just as in the fopen function. The primary use of the ffrreeooppeenn() function is to change the file associated with a standard text stream (_s_t_d_e_r_r, _s_t_d_i_n, or _s_t_d_o_u_t). RREETTUURRNN VVAALLUUEESS Upon successful completion ffooppeenn(), ffddooppeenn() and ffrreeooppeenn() return a FILE pointer. Otherwise, NULL is returned and the global variable _e_r_r_n_o is set to indicate the error. EERRRROORRSS [EINVAL] The _m_o_d_e provided to ffooppeenn(), ffddooppeenn(), or ffrreeooppeenn() was in- valid. The ffooppeenn(), ffddooppeenn() and ffrreeooppeenn() functions may also fail and set _e_r_r_n_o for any of the errors specified for the routine malloc(3). The ffooppeenn() function may also fail and set _e_r_r_n_o for any of the errors specified for the routine open(2). The ffddooppeenn() function may also fail and set _e_r_r_n_o for any of the errors specified for the routine fcntl(2). The ffrreeooppeenn() function may also fail and set _e_r_r_n_o for any of the errors specified for the routines open(2), fclose(3) and fflush(3). SSEEEE AALLSSOO open(2), fclose(3), fseek(3), funopen(3) SSTTAANNDDAARRDDSS The ffooppeenn() and ffrreeooppeenn() functions conform to ANSI C X3.159-1989 (``ANSI C ''). The ffddooppeenn() function conforms to IEEE Std1003.1-1988 (``POSIX''). 4.4BSD June 4, 1993 2