Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fopen(3ucb) [sunos man page]

fopen(3UCB)					     SunOS/BSD Compatibility Library Functions					       fopen(3UCB)

NAME
fopen, freopen - open a stream SYNOPSIS
/usr/ucb/cc[ flag ... ] file ... #include <stdio.h> FILE *fopen( file, mode); const char *file, *mode; FILE *freopen(file, mode, iop); const char *file, *mode; register FILE *iop; DESCRIPTION
The fopen() function opens the file specified by file and associates a stream with it. If the open succeeds, fopen() returns a pointer to be used to identify the stream in subsequent operations. The file argument points to a character string that contains the name of the file to be opened. The mode argument is a character string having one of the following values: r open for reading w truncate or create for writing a append: open for writing at end of file, or create for writing r+ open for update (reading and writing) w+ truncate or create for update a+ append; open or create for update at EOF The freopen() function opens the file specified by file and associates the stream pointed to by iop with it. The mode argument is used just as in fopen(). The original stream is closed, regardless of whether the open ultimately succeeds. If the open succeeds, freopen() returns the original value of iop. The freopen() function is typically used to attach the preopened streams associated withstdin, stdout, and stderr to other files. When a file is opened for update, both input and output can be performed on the resulting stream. Output cannot be directly followed by input without an intervening fseek(3C) or rewind(3C). Input cannot be directly followed by output without an intervening fseek(3C) or rewind(3C). An input operation that encounters EOF will fail. RETURN VALUES
The fopen() and freopen() functions return a NULL pointer on failure. USAGE
The fopen() and freopen() functions have transitional interfaces for 64-bit file offsets. See lf64(5). SEE ALSO
open(2), fclose(3C), fopen(3C), freopen(3C), fseek(3C), malloc(3C), rewind(3C), lf64(5) NOTES
Use of these functions should be restricted to applications written on BSD platforms. Use of these functions with any of the system libraries or in multithreaded applications is unsupported. To support the same number of open files as the system, fopen() must allocate additional memory for data structures using malloc(3C) after 64 files have been opened. This confuses some programs that use their own memory allocators. The fopen() and freopen() functions differ from the standard I/O functions fopen(3C) and freopen(3C). The standard I/O functions distin- guish binary from text files with an additional use of 'b' as part of the mode, enabling portability of fopen(3C) and freopen(3C) beyond SunOS 4.x systems. SunOS 5.10 22 Jan 1993 fopen(3UCB)

Check Out this Related Man Page

fopen(3s)																 fopen(3s)

Name
       fopen, freopen, fdopen - open a stream

Syntax
       #include <stdio.h>

       FILE *fopen (filename, type)
       char *filename, *type;

       FILE *freopen (filename, type, stream)
       char *filename, *type;
       FILE *stream;

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

Description
       The  routine opens the file named by filename and associates a stream with it.  The routine returns a pointer to the FILE structure associ-
       ated with the stream.

       The filename points to a character string that contains the name of the file to be opened.

       The type is a character string having one of the following values:

	  "r"	    Open for reading

	  "w"	    Truncate or create for writing

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

	  "A"	    Append with no overwrite; open for writing at end-of-file, or create for writing

	  "r+"	    Open for reading and writing

	  "w+"	    Truncate or create for reading and writing

	  "a+"	    Append; open or create for reading and writing at end-of-file

	  "A+"	    Append with no overwrite, open or create for update at end-of-file

       The letter "b" can also follow r, w, or a. In some C implementations, the "b" is needed to indicate a  binary  file,  however,  it  is  not
       needed in ULTRIX.  If "+" is used, the "b" may occur on either side, as in "rb+" or "w+b".

       The  routine  substitutes  the named file in place of the open stream.  The original stream is closed, regardless of whether the open ulti-
       mately succeeds.  The routine returns a pointer to the FILE structure associated with stream.

       The routine is typically used to attach the preopened streams associated with stdin, stdout and stderr to other files.

       The routine associates a stream with a file descriptor.	File descriptors are obtained from or 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.

       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  or and input may not be directly followed by output without an intervening or an input operation which
       encounters end-of-file.

       When a file is opened for append with no overwrite (that is when type is "A" or "A+"), it is impossible to overwrite information already in
       the  file.  The routine 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 output 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 process 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 in which it is
       written.

Return Values
       The and routines return a NULL pointer on failure.

Environment
   SYSTEM_V
       When  your  program is compiled using the System V environment, append with no overwrite is specified by using the "a" or "a+" type string,
       and the "A" and "A+" type strings are not allowed.

   POSIX
       In the POSIX environment, the "a" and "a+" strings, and the "A" and "A+" strings specify append with no overwrite.

See Also
       creat(2), dup(2), open(2), pipe(2), fclose(3s), fseek(3s).

																	 fopen(3s)
Man Page