Syntax | #include <sys/types.h> int open (const char *path, int oflag , .../* mode_t mode*/); | |||||||||||||||||||||||||
Description | If POSIX files are executed, the behavior of this function conforms to the XPG4 standard as described below: The
The file position indicator is set to the beginning of the file. The file status byte and file access modes of the open file description will be set according to the value of oflag. Values for oflag are constructed by a bitwise-inclusive-OR of flags from the following list, defined in
Any combination of the following flags may be used:
If If There is no difference in functionality between If threads are used, then the function affects the process or a thread in the following manner: Opening a file; If Extension BS2000 const char *path is a string specifying the file to be opened. path can be any valid BS2000 file name.
oflag is a constant defined in the <stdio.h> header which specifies the desired access mode (or the corresponding octal value), namely:
Open for reading. The file must already exist.
Open for writing. The file must already exist. The previous contents are retained.
Open for writing. If the file exists, the previous contents are deleted. If the file does not exist, it is created.
Open for reading and writing. The file must already exist. The previous contents are retained.
Open for reading and writing. If the file exists, the previous contents are deleted. If the file does not exist, it is created.
Open for writing and reading. If the file exists, the previous contents are deleted. If the file does not exist, it is created.
Open for appending to the end of the file. The file must already exist. The file is positioned to end of file, i.e. the previous contents are preserved and the new text is appended to the end of the file.
Open for appending to the end of the file and for reading. The file must already exist. The old contents are preserved and the new text is appended to the end of the file. After it is opened, the file is positioned to the end of the file when KR functionality is being used (applies to C/C++ versions prior to V3.0 only), with ANSI functionality to the start of the file. lbp switch The lbp switch controls handling of the Last Byte Pointer (LBP). It is only relevant for binary files with PAM access mode and can be combined with all specifications permissible for When an existing file is opened and read, the LBP is always taken into account independently of the lbp switch:
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.
When a file which has been modified or 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 or newly created is closed, the LBP is set to zero (=invalid). 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 specified in both variants ( 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 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. It can be combined with any of the other constants.
When reading with If the switch is not specified, the following applies:
The constant
This switch functions as follows:
(End) The The oflag parameter and the optional fourth parameter fmode correspond exactly to the parameters of When the value | |||||||||||||||||||||||||
Return val. | Non-negative integer | |||||||||||||||||||||||||
indicating the the lowest numbered unused file descriptor, if successful. | ||||||||||||||||||||||||||
| -1 | if an error occurs. No file is created or updated. | ||||||||||||||||||||||||
Errors |
| |||||||||||||||||||||||||
|
| Search permission is denied on a component of the path. The file does not exist, and the access permissions specified by oflag are denied. The file does not exist, and write permission is denied by the parent directory of the file to be created.
| ||||||||||||||||||||||||
| Extension | |||||||||||||||||||||||||
|
| The file exists, mandatory file/record locking is set, and there are outstanding record locks on the file (see | ||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||
|
| path points beyond the assigned address space of the process. | ||||||||||||||||||||||||
|
| A signal was caught during the | ||||||||||||||||||||||||
|
| The value of the oflag argument is invalid. | ||||||||||||||||||||||||
|
| A connection was cleared or an error occurred while opening a stream-oriented device. | ||||||||||||||||||||||||
| The named file is a directory and oflag includes | |||||||||||||||||||||||||
|
| |||||||||||||||||||||||||
| Components of path require hops to several remote computers, but the file system does not permit this. | |||||||||||||||||||||||||
| ||||||||||||||||||||||||||
The length of the path argument exceeds | ||||||||||||||||||||||||||
| The maximum allowable number of files is currently open in the system. | |||||||||||||||||||||||||
|
| |||||||||||||||||||||||||
| path refers to a remote computer to which there is no active connection. | |||||||||||||||||||||||||
| The file does not exist, and | |||||||||||||||||||||||||
| A stream cannot be assigned. | |||||||||||||||||||||||||
| 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 this special file does not exist, or | |||||||||||||||||||||||||
| The named file resides on a read-only file system and either | |||||||||||||||||||||||||
|
| |||||||||||||||||||||||||
In addition, | ||||||||||||||||||||||||||
| The fd parameter was not opened with | |||||||||||||||||||||||||
| The path parameter does not specify an absolute pathname, and the fd parameter does not have the value | |||||||||||||||||||||||||
| The path parameter does not specify an absolute pathname, and the file descriptor fd is not connected with a directory. | |||||||||||||||||||||||||
| The implementation does not support | |||||||||||||||||||||||||
Notes | The program environment determines whether BS2000 Non-existent files are created by default with the following attributes: for KR functionality (only available with C/C++ versions lower than V3), as a SAM file with variable record length and standard block length; for ANSI functionality, as an ISAM file with variable record length and standard block length. SAM files are always opened as text files by If a link name is used, the following file attributes may be changed with the Location of the file position indicator in append mode: If the file-position indicator of a file opened in append mode (0401, 0402) has been explicitly moved from the end of the file ( An attempt to open a non-existent file in the read (0000, 0002), update (0001), or append (0401, 0402) mode will result in an error. A file may be opened for different access modes simultaneously, provided these modes are mutually compatible within the BS2000 data management system. (INCORE) files can only be opened for writing (01001) or for writing and reading (0003). Data must first be written. To read in the written data again, the file must be positioned to beginning of file with the When a program starts, the standard files for input, output, and error output are automatically opened with the following file descriptors:
(End) A maximum of _NFILE files may be open simultaneously. _NFILE is defined as 2048 in | |||||||||||||||||||||||||
See also |
|