| Open (system Call) |
Article Index for Open |
Website Links For Open |
Information AboutOpen (system Call) |
|
After using the file, the process should use the Close system call. This system call usually takes some arguments indicating a file path, the kind of access requested on the file (read, write, append, etc.) and how the file information should be interprated (text, binary, record-based). In several operating systems this system call can also be used to create a non existent file and returning a file descriptor for it. POSIX USAGE AND SEMANTICS The open system call interface is standarized by the POSIX specification. A file is opened or created by calling the open function:
The value returned is the new file descriptor (in POSIX, file descriptors are non-negative integer values). This integer is usually an index on a table of open files for the process. The operating system keeps independent tables for different processes. The file descriptor contains, among other things, a position pointer that indicates which place of the file will be acted upon by further file operations. The same filesystem file can be opened simultaneously by several processes, and even by the same process (resulting in several file descriptors for the same file). Operations on the descriptors like moving the file pointer, or closing it are independent (they do not affect other descriptors for the same physical file). However, operations of the physical file (like a write) can be seen by operations on the other descriptors (a posterior read can read the written data) Alternatively, open can return a negative number indicating that the open operation failed The ''pathname'' argument is the name of the file to open. It is a File Path indicating in which place of the file system the file should be found (or created if that is requested) There are a multiple options for this function, which are apecified by the ''oflag'' argument. This argument formed by OR'ing together one or more of the following constants (from ;O_RDONLY :Open for reading only, ;O_WRONLY :Open for writing only, ;O_RDWR :Open for reading and writing, Optionally, you can also use the following parameters (the following list is not exhaustive, it intends to show what kind of options can be used with open): ;O_APPEND :When using this flag, all data written will be appended to the end of the file. The file operations will ignore the position pointer inside the file descriptor and always append at the end of the file, even when other processes are also accessing the file ;O_CREAT :This flag will make open to create the file if it does not exist, or overwrite and existing one. ;O_EXCL :When this flag is used with O_CREAT, it avoids the overwriting behaviour. ;O_NONBLOCK :Operations on the file descriptor will return control to the process immediately instead of waiting to finish. the ''mode_t'' argument is optional, and is relevant only when creating a new file. It indicates the file permissions for the newly created file. REFERENCE
|
|
|