Syntax | #include <stdio.h> FILE *fopen(const char *filename, const char *mode); | |||||||||||||||||||||||||||||||||||||||
Description | Description a stream with it. filename can be:
mode is a string that specifies the desired access mode. It can have one of the following values:
The character Opening a file with append mode (i.e. with When a file is opened with update mode (i.e. with When opened, a stream is fully buffered if and only if it can be determined not to refer to an interactive device such as the terminal. The error and end-of-file indicators for the stream are cleared. For automatic conversion, the BS2000
Tab character (\t) Additionally to the access mode an optional entry to control handling of the tab character (
The tab character is expanded into the appropriate number of blanks. This is the default setting for KR functionality (only available with C/C++ versions lower than V3).
The tab character is not expanded. This is the default setting for ANSI functionality. Last Byte Pointer (LBP) In the mode parameter an optional entry controlling how the Last Byte Pointer (LBP) is to be handled can be specified in addition to the access mode. This is relevant only for binary files with PAM access mode. If When an existing file is opened and read, the LBP is always taken into account independently of the lbp switch:
"...,lbp=yes" When a file which has been modified or newly created is closed, no marker is written (even if one was present), and a valid LBP is set. In this way files with a marker can be converted to LBP without a marker. In the case of NK files the last logical block is padded with binary zeros, in the case of K files the file is padded to the physical end of file. "...,lbp=no" When a file which has been newly created is closed, the LBP is set to zero (=invalid). A marker is written. In the case of NK files the last logical block is padded with binary zeros, in the case of K files the file is padded to the physical end of file. When a file which has been modified is closed, the LBP is set to zero (=invalid). A marker is written only if a marker existed before. If no marker existed, none is written and the file ends with the complete last block. If the file had a valid LBP when it was opened, no marker is written as in this case it is assumed that no marker exists. In the case of NK files the last logical block is padded with binary zeros, in the case of K files the file is padded to the physical end of file. If the lbp switch is not specified, the behavior depends on the environment variable LAST_BYTE_POINTER (see also section “Environment variables”):
The function behaves as if
The function behaves as if Split/Nosplit switch This switch controls the processing of text files with SAM access mode and variable record length when a maximum record length is also specified. "...,split=yes"
"...,split=no" When reading, records of maximum length are not concatenated with the following record. When reading with one of the functions If the switch is not specified, "...,split=yes" applies. There is no difference in functionality between | |||||||||||||||||||||||||||||||||||||||
Return val. | File pointer Null pointer | if successful. if filename cannot be accessed, mode is invalid, or the file cannot be opened. | ||||||||||||||||||||||||||||||||||||||
Errors |
| |||||||||||||||||||||||||||||||||||||||
|
| Search permission is denied on a component of the path prefix, | ||||||||||||||||||||||||||||||||||||||
|
| A signal was caught during the | ||||||||||||||||||||||||||||||||||||||
|
| The value of the mode argument is invalid. | ||||||||||||||||||||||||||||||||||||||
|
| The named file is a directory and mode requires write access. | ||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||
The length of filename exceeds | ||||||||||||||||||||||||||||||||||||||||
|
| The maximum allowable number of files is currently open in the system. | ||||||||||||||||||||||||||||||||||||||
|
| The named file does not exist or filename points to an empty string. | ||||||||||||||||||||||||||||||||||||||
|
| There is not enough memory available. | ||||||||||||||||||||||||||||||||||||||
|
| The file does not exist, and the directory in which the new file is to be created cannot be expanded. | ||||||||||||||||||||||||||||||||||||||
|
| A component of the path is not a directory. | ||||||||||||||||||||||||||||||||||||||
|
| The named file is a character special or block special file, and the device associated with this special file does not exist. | ||||||||||||||||||||||||||||||||||||||
|
| The named file resides on a read-only file system and mode requires write | ||||||||||||||||||||||||||||||||||||||
| The file is a pure procedure file (shared text file) that is currently executing and write protection is required for | |||||||||||||||||||||||||||||||||||||||
| The file named is a regular file and the size of the file cannot be represented correctly in an object of type | |||||||||||||||||||||||||||||||||||||||
Notes |
defined, it has the same value as The program environment determines whether BS2000 System files and ISAM files are always processed as text files. Specifying binary mode for these files leads to an error on opening. (INCORE) and PAM files are always processed as binary files. For compatibility reasons, files may be opened as binary files without explicitly specifying the binary mode. When a new file is created it is given the following attributes by default:
The following file attributes can be changed by using a link name with the Whenever the old contents of an existing file are deleted (i.e. when a file is opened for rewriting or for rewriting and reading), the catalog attributes of that file are preserved. When a file is opened for an update, reading and writing can be performed via the same file pointer. All the same, an output should not be immediately followed by an input without a preceding positioning operation (with Set the file position indicator in append mode(INCORE) files can only be opened for writing ( A file may be opened for different access modes simultaneously, provided these modes are compatible with one another within the BS2000 data management system. When a program begins, the following three file pointers are assigned to it automatically:
A maximum of _NFILE files may be open simultaneously. _NFILE is defined as 2048 in For opening files with record I/O, the mode parameter has two additional options. These follow the access mode in the string (see above), each separated by a comma:
If If The following restrictions apply to record I/O. If these restrictions are ignored, the file is not opened, and an error value is returned:The file must be opened in binary mode (
The append mode | |||||||||||||||||||||||||||||||||||||||
See also |
|