BSD 4_4 development
[unix-history] / usr / share / man / cat3 / fopen.0
index d9c322c..895c13f 100644 (file)
-
-
-
-FOPEN(3)                     1989                       FOPEN(3)
-
-
+FOPEN(3)                    BSD Programmer's Manual                   FOPEN(3)
 
 N\bNA\bAM\bME\bE
 
 N\bNA\bAM\bME\bE
-     fopen, freopen, fdopen - open a stream
+     f\bfo\bop\bpe\ben\bn, f\bfd\bdo\bop\bpe\ben\bn, f\bfr\bre\beo\bop\bpe\ben\bn - stream open functions
 
 S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
      #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bst\btd\bdi\bio\bo.\b.h\bh>\b>
 
 
 S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
      #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bst\btd\bdi\bio\bo.\b.h\bh>\b>
 
-     F\bFI\bIL\bLE\bE *\b*f\bfo\bop\bpe\ben\bn(\b(f\bfi\bil\ble\ben\bna\bam\bme\be,\b, t\bty\byp\bpe\be)\b)
-     c\bch\bha\bar\br *\b*f\bfi\bil\ble\ben\bna\bam\bme\be,\b, *\b*t\bty\byp\bpe\be;\b;
+     _\bF_\bI_\bL_\bE _\b*
+     f\bfo\bop\bpe\ben\bn(_\bc_\bh_\ba_\br _\b*_\bp_\ba_\bt_\bh, _\bc_\bh_\ba_\br _\b*_\bm_\bo_\bd_\be);
 
 
-     F\bFI\bIL\bLE\bE *\b*f\bfr\bre\beo\bop\bpe\ben\bn(\b(f\bfi\bil\ble\ben\bna\bam\bme\be,\b, t\bty\byp\bpe\be,\b, s\bst\btr\bre\bea\bam\bm)\b)
-     c\bch\bha\bar\br *\b*f\bfi\bil\ble\ben\bna\bam\bme\be,\b, *\b*t\bty\byp\bpe\be;\b;
-     F\bFI\bIL\bLE\bE *\b*s\bst\btr\bre\bea\bam\bm;\b;
+     _\bF_\bI_\bL_\bE _\b*
+     f\bfd\bdo\bop\bpe\ben\bn(_\bi_\bn_\bt _\bf_\bi_\bl_\bd_\be_\bs, _\bc_\bh_\ba_\br _\b*_\bm_\bo_\bd_\be);
 
 
-     F\bFI\bIL\bLE\bE *\b*f\bfd\bdo\bop\bpe\ben\bn(\b(f\bfi\bil\bld\bde\bes\bs,\b, t\bty\byp\bpe\be)\b)
-     c\bch\bha\bar\br *\b*t\bty\byp\bpe\be;\b;
+     _\bF_\bI_\bL_\bE _\b*
+     f\bfr\bre\beo\bop\bpe\ben\bn(_\bc_\bh_\ba_\br _\b*_\bp_\ba_\bt_\bh, _\bc_\bh_\ba_\br _\b*_\bm_\bo_\bd_\be, _\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm);
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     _\bF_\bo_\bp_\be_\bn opens the file named by _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be and associates a
-     stream with it.  _\bF_\bo_\bp_\be_\bn returns a pointer to be used to iden-
-     tify the stream in subsequent operations.
-
-     _\bT_\by_\bp_\be 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 _\bt_\by_\bp_\be 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 _\bf_\bs_\be_\be_\bk, _\br_\be_\bw_\bi_\bn_\bd, or reading an end-of-file must
-     be used between a read and a write or vice-versa.
-
-     _\bF_\br_\be_\bo_\bp_\be_\bn substitutes the named file in place of the open
-     _\bs_\bt_\br_\be_\ba_\bm.  It returns the original value of _\bs_\bt_\br_\be_\ba_\bm. The ori-
-     ginal stream is closed.
-
-     _\bF_\br_\be_\bo_\bp_\be_\bn is typically used to attach the preopened constant
-     names, s\bst\btd\bdi\bin\bn,\b, s\bst\btd\bdo\bou\but\bt,\b, s\bst\btd\bde\ber\brr\br,\b, to specified files.
-
-     _\bF_\bd_\bo_\bp_\be_\bn associates a stream with a file descriptor obtained
-     from _\bo_\bp_\be_\bn, _\bd_\bu_\bp, _\bc_\br_\be_\ba_\bt, or _\bp_\bi_\bp_\be(2).  The _\bt_\by_\bp_\be of the stream
-     must agree with the mode of the open file.
-
-S\bSE\bEE\bE A\bAL\bLS\bSO\bO
-     open(2), fclose(3)
-
-
-
-Printed 7/27/90               April                            1
-
-
-
-
-
-
-FOPEN(3)                     1989                       FOPEN(3)
-
+     The f\bfo\bop\bpe\ben\bn() function opens the file whose name is the string pointed to
+     by _\bp_\ba_\bt_\bh and associates a stream with it.
 
 
+     The argument _\bm_\bo_\bd_\be points to a string beginning with one of the following
+     sequences (Additional characters may follow these sequences.):
 
 
-D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS
-     _\bF_\bo_\bp_\be_\bn and _\bf_\br_\be_\bo_\bp_\be_\bn return the pointer N\bNU\bUL\bLL\bL if _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be cannot
-     be accessed, if too many files are already open, or if other
-     resources needed cannot be allocated.
+     ``r''   Open text file for reading.  The stream is positioned at the be-
+             ginning of the file.
 
 
-B\bBU\bUG\bGS\bS
-     _\bF_\bd_\bo_\bp_\be_\bn is not portable to systems other than UNIX.
+     ``r+''  Open for reading and writing.  The stream is positioned at the
+             beginning of the file.
 
 
-     The read/write _\bt_\by_\bp_\be_\bs do not exist on all systems.       Those
-     systems without read/write modes will probably treat the
-     _\bt_\by_\bp_\be as if the "+" was not present.  These are unreliable in
-     any event.
+     ``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.
 
 
-     In order to support the same number of open files as does
-     the system, _\bf_\bo_\bp_\be_\bn must allocate additional memory for data
-     structures using _\bc_\ba_\bl_\bl_\bo_\bc after 20 files have been opened.
-     This confuses some programs which use their own memory allo-
-     cators.  An undocumented routine, _\bf__\bp_\br_\be_\ba_\bl_\bl_\bo_\bc, may be called
-     to force immediate allocation of all internal memory except
-     for buffers.
+     ``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 _\bm_\bo_\bd_\be 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 _\bs_\bt_\bd_\bi_\bo.
+     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 f\bfd\bdo\bop\bpe\ben\bn() function associates a stream with the existing file descrip-
+     tor, _\bf_\bi_\bl_\bd_\be_\bs. The _\bm_\bo_\bd_\be of the stream must be compatible with the mode of
+     the file descriptor.
 
 
+     The f\bfr\bre\beo\bop\bpe\ben\bn() function opens the file whose name is the string pointed to
+     by _\bp_\ba_\bt_\bh and associates the stream pointed to by _\bs_\bt_\br_\be_\ba_\bm with it.  The
+     original stream (if it exists) is closed.  The _\bm_\bo_\bd_\be argument is used just
+     as in the fopen function.  The primary use of the f\bfr\bre\beo\bop\bpe\ben\bn() function is
+     to change the file associated with a standard text stream (_\bs_\bt_\bd_\be_\br_\br, _\bs_\bt_\bd_\bi_\bn,
+     or _\bs_\bt_\bd_\bo_\bu_\bt).
 
 
+R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bES\bS
+     Upon successful completion f\bfo\bop\bpe\ben\bn(), f\bfd\bdo\bop\bpe\ben\bn() and f\bfr\bre\beo\bop\bpe\ben\bn() return a FILE
+     pointer.  Otherwise, NULL is returned and the global variable _\be_\br_\br_\bn_\bo is
+     set to indicate the error.
 
 
+E\bER\bRR\bRO\bOR\bRS\bS
+     [EINVAL]  The _\bm_\bo_\bd_\be provided to f\bfo\bop\bpe\ben\bn(), f\bfd\bdo\bop\bpe\ben\bn(), or f\bfr\bre\beo\bop\bpe\ben\bn() was in-
+               valid.
 
 
+     The f\bfo\bop\bpe\ben\bn(), f\bfd\bdo\bop\bpe\ben\bn() and f\bfr\bre\beo\bop\bpe\ben\bn() functions may also fail and set _\be_\br_\br_\bn_\bo
+     for any of the errors specified for the routine malloc(3).
 
 
+     The f\bfo\bop\bpe\ben\bn() function may also fail and set _\be_\br_\br_\bn_\bo for any of the errors
+     specified for the routine open(2).
 
 
+     The f\bfd\bdo\bop\bpe\ben\bn() function may also fail and set _\be_\br_\br_\bn_\bo for any of the errors
+     specified for the routine fcntl(2).
 
 
+     The f\bfr\bre\beo\bop\bpe\ben\bn() function may also fail and set _\be_\br_\br_\bn_\bo for any of the errors
+     specified for the routines open(2),  fclose(3) and fflush(3).
 
 
+S\bSE\bEE\bE A\bAL\bLS\bSO\bO
+     open(2),  fclose(3),  fseek(3),  funopen(3)
 
 
+S\bST\bTA\bAN\bND\bDA\bAR\bRD\bDS\bS
+     The f\bfo\bop\bpe\ben\bn() and f\bfr\bre\beo\bop\bpe\ben\bn() functions conform to ANSI C X3.159-1989 (``ANSI
+     C ''). The f\bfd\bdo\bop\bpe\ben\bn() function conforms to IEEE Std1003.1-1988 (``POSIX'').
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Printed 7/27/90               April                            2
-
-
-
+4.4BSD                           June 4, 1993                                2