HPUX fdopen[3s]






 fopen(3S)                                                         fopen(3S)





 NAME
      fopen(), freopen(), fdopen() - open or re-open a stream file; convert
      file to stream

 SYNOPSIS
      #include <stdio.h>

      FILE *fopen(const char *pathname, const char *type);

      FILE *freopen(const char *pathname, const char *type, FILE *stream);

      FILE *fdopen(int fildes, const char *type);

 DESCRIPTION
      fopen()        Opens the file named by pathname and associates a
                     stream with it.  fopen() returns a pointer to the FILE
                     structure associated with the stream.

      freopen()      substitutes the named file in place of the open stream.
                     The original stream is closed, regardless of whether
                     the open ultimately succeeds.  freopen() returns a
                     pointer to the FILE structure associated with stream
                     and makes an implicit call to clearerr() (see
                     ferror(3S)).

                     freopen() is typically used to attach the preopened
                     streams associated with stdin, stdout, and stderr to
                     other files.

      fdopen()       associates a stream with a file descriptor.  File
                     descriptors are obtained from open(), dup(), creat(),
                     or pipe() (see open(2), dup(2), creat(2), and pipe(2)),
                     which open files but do not return pointers to a FILE
                     structure stream.  Streams are necessary input for many
                     of the Section (3S) library routines.  The type of
                     stream must agree with the mode of the open file.  The
                     meanings of type used in the fdopen() call are exactly
                     as specified above, except that w, w+, wb, and wb+ do
                     not cause truncation of the file.

      pathname       Points to a character string containing the name of the
                     file to be opened.

      type           Character string having one of the following values:

                          r              open for reading

                          w              truncate to zero length or create
                                         for writing





 Hewlett-Packard Company            - 1 -     HP-UX Release 9.0: August 1992






 fopen(3S)                                                         fopen(3S)





                          a              append; open for writing at end of
                                         file, or create for writing

                          rb             open binary file for reading

                          wb             truncate to zero length or create
                                         binary file for writing

                          ab             append; open binary file for
                                         writing at end-of-file, or create
                                         binary file

                          r+             open for update (reading and
                                         writing)

                          w+             truncate to zero length or create
                                         for update

                          a+             append; open or create for update
                                         at end-of-file

                          r+b or rb+     open binary file for update
                                         (reading and writing)

                          w+b or wb+     truncate to zero length or create
                                         binary file for update

                          a+b or ab+     append; open or create binary file
                                         for update at end-of-file

      When a file is opened for update, both input and output can be done on
      the resulting stream.  However, output cannot be directly followed by
      input without an intervening call to fflush() or to a file positioning
      function (fseek(), fsetpos(), or rewind()), and input cannot be
      directly followed by output without an intervening call to a file
      positioning function unless the input operation encounters end-of-
      file.

      When a file is opened for append (i.e., when type is a or a+), it is
      impossible to overwrite information already in the file.  All output
      is written at the end of the file, regardless of intervening calls to
      fseek().  If two separate processes open the same file for append,
      each process can write freely to the file without fear of destroying
      output being written by the other.  Output from the two processes will
      be intermixed in the file in the order in which it is written.

 RETURN VALUE
      Upon successful completion, fopen(), fdopen(), and freopen() return a
      FILE * pointer to the stream.  Otherwise, a null pointer is returned
      and errno is set to indicate the error.




 Hewlett-Packard Company            - 2 -     HP-UX Release 9.0: August 1992






 fopen(3S)                                                         fopen(3S)





 ERRORS
      fopen(), fdopen(), and freopen() fail if:

      [EINVAL]       The type argument is not a valid mode.

      [ENOMEM]       There is insufficient space to allocate a buffer.

      fopen() and freopen() fail if:

      [EACCES]       Search permission is denied on a component of the path
                     prefix, or the file exists and the permissions
                     specified by type are denied, or the file does not
                     exist and write permission is denied for the parent
                     directory of the file to be created.

      [EINTR]        A signal was caught during fopen() or freopen().
                     function.

      [EISDIR]       The named file is a directory and type requires write
                     access.

      [EMFILE]       The calling process has attempted to exceed its open
                     file limit.

      [ENAMETOOLONG] The length of the pathname string exceeds PATH_MAX or a
                     pathname component is longer than NAME_MAX while
                     POSIX_NO_TRUNC is in effect.

      [ENFILE]       The system file table is full.

      [ENOENT]       The named file does not exist or the pathname argument
                     points to an empty string.

      [ENOSPC]       The directory or file system that would contain the new
                     file cannot be expanded, the file does not exist, and
                     it was to be created.

      [ENOTDIR]      A component of the path prefix is not a directory.

      [ENXIO]        The named file is a character special or block special
                     file, and the device associated with the special file
                     does not exist.

      [EROFS]        The named file resides on a read-only file system and
                     type requires write access.

      Additional errno values can be set by the underlying open() call made
      from the fopen() and freopen() functions (see open(2)).

 NOTES
      HP-UX binary file types are equivalent to their non-binary



 Hewlett-Packard Company            - 3 -     HP-UX Release 9.0: August 1992






 fopen(3S)                                                         fopen(3S)





      counterparts.  For example, types r and rb are equivalent.

 SEE ALSO
      creat(2), dup(2), open(2), pipe(2), fclose(3S), fseek(3S), popen(3S),
      setvbuf(3S).

 STANDARDS CONFORMANCE
      fopen(): AES, SVID2, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

      fdopen(): AES, SVID2, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

      freopen(): AES, SVID2, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C










































 Hewlett-Packard Company            - 4 -     HP-UX Release 9.0: August 1992