Definition | #include <stdio.h> int creat(const char *f_name, int mode);
There is no functional difference between To process files > 2 GB, proceed as follows:
| |
Parameters | const char *f_name A string specifying the name of the file to be opened. f_name can be:
int mode In BS2000 only the lbp switch,the nosplit switch and the O_RECORD entry are evaluated here. All other specifications in this parameter are ignored. However, they are necessary to create portable programs as they regulate protection bit assignment in the UNIX operating system. 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 a file which has been newly created is closed, no marker is written and a valid LBP is set.
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. If the lbp switch is specified in both variants (O_LBP and O_NOLBP), the If the lbp switch is not specified, the behavior depends on the environment variable LAST_BYTE_POINTER (see also “Environment variable LAST_BYTE_POINTER” (Last Byte Pointer (LBP))):
The function behaves as if O_LBP were specified.
The function behaves as if O_NOLBP were specified. 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 writing with If the switch is not specified, the following applies when writing: A record which is longer than the maximum record length will be split into multiple records. If a record has precisely the maximum record length, a record of the length zero is written after it. | |
Return val. | File descriptor | positive number used later to identify the file in elementary access operations ( |
-1 | if the file could not be opened, e.g. because too many files are open or because f_name is not a valid file or link name. | |
Notes | The BS2000 file name or link name may be written in lowercase and uppercase letters. It is automatically converted to uppercase letters. If a non-existent file is created, the following applies by default: By using a link name the following file attributes can be changed with the ADD-FILE-LINK command: access method, record length, record format, block length and block format. See also section “System files (SYSDTA, SYSOUT, SYSLST)”. If an existing file is truncated to length 0, the catalog attributes of this file are preserved. A maximum of _NFILE files may be open simultaneously. _NFILE is defined as 2048 in <stdio.h>. | |
Record I/O | The constant O_RECORD can be specified in the modus parameter to open files with record-oriented input/output (record I/O). It can always be combined with every other constant except O_LBP.
This switch functions as follows: The | |
Satz-E/A | Zum Eröffnen von Dateien mit satzorientierter Ein-/Ausgabe (Satz-E/A) kann beim Parameter modus die Konstante O_RECORD angegeben werden. Sie kann grundsätzlich mit jeder anderen Konstanten außer O_LBP kombiniert werden.
Dieser Schalter bewirkt Folgendes: Die Funktion | |
Example | The program given below writes the contents of an input file to an output file. The output file is created as a new file with creat. The name of this file as well as the file attributes are defined by means of a ADD-FILE-LINK command (link name=LINK). /ADD-FILE-LINK LINK-NAME=LINK,FILE-NAME=OUT.ISAM,ACCESS-METHOD=ISAM #include <stdio.h> #include <stdlib.h> int main(void) { char name[50]; char buf; int fin, fout; printf("Name of the input file?\n"); gets(name); printf("File %s is being copied.\n", name); if ((fin = open(name,0)) == -1) { perror(name); exit(-1); } if ((fout = creat("link=link", 1)) == -1) { perror("link"); exit(-1); } while(read(fin, &buf, 1) > 0) { putchar(buf); /* Log to stdout */ write(fout, &buf, 1); } close(fin); close(fout); return 0; } | |
See also | close, fdopen, open, open64, read, write, perror |