Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

(hpux section 3s)
man page for fopen

fopen(3S)																 fopen(3S)

fopen(), freopen(), fdopen() - open/reopen a stream file or convert file to stream SYNOPSIS
Opens the file named by pathname and associates a stream with it. returns a pointer to the structure associated with the stream. substitutes the named file in place of the open stream. The original stream is closed, regardless of whether the open ultimately succeeds. returns a pointer to the struc- ture associated with stream and makes an implicit call to (see ferror(3S)). After a successful call to the orientation of the stream is cleared (see orientation(5)). is typically used to attach the preopened streams associated with and to other files. associates a stream with a file descriptor. File descriptors are obtained from or (see open(2), dup(2), creat(2), and pipe(2)), which open files but do not return pointers to a 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 call are exactly as specified above, except that and 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 values listed below. The in the following values has no effect. It exists to distin- guish binary files from text files; however, there is no distinction between these types of files on UNIX systems (it is required for ISO C standard conformance). r or rb open file for reading w or wb truncate to zero length or create file for writing a or ab append; open file for writing at end of file, or create file or writing r+, rb+, or r+b open file for update (reading and writing) w+, wb+, or w+b truncate file to zero length or create file for update a+, ab+, or a+b append; open or create 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 or to a file positioning function or 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 (that is, when type is or 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 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 inter- mixed in the file in the order in which it is written. Notes HP-UX binary file types are equivalent to their non-binary counterparts. For example, types and are equivalent. RETURN VALUE
Upon successful completion, and return a pointer to the stream. Otherwise, a null pointer is returned and is set to indicate the error. ERRORS
and fail if: The fildes argument is not a valid file descriptor. The type argument is not a valid mode. There is insufficient space to allocate a buffer. and fail if: 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. A signal was caught during or function. The named file is a directory and type requires write access. The calling process has attempted to exceed its open file limit. The length of the pathname string exceeds or a pathname component is longer than while is in effect. The system file table is full. The named file does not exist or the pathname argument points to an empty string. 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. A component of the path prefix is not a directory. The named file is a character special or block special file, and the device associated with the special file does not exist. The named file is a regular file and the size of the file cannot be represented correctly in an object of size in this environment. The named file resides on a read-only file system and type requires write access. Additional values can be set by the underlying call made from the and functions (see open(2)). SEE ALSO
creat(2), dup(2), open(2), pipe(2), fclose(3S), fgetpos64(3S), fseek(3S), popen(3S), setbuf(3S), orientation(5), thread_safety(5), glos- sary(9). STANDARDS CONFORMANCE

Featured Tech Videos