#include <stdio.h> ret = fopen( name, options )
"fopen" opens a file for subsequent reading or writing. If successful, "fopen" returns a pointer-to-structure; if it fails, it returns NULL.
"name" is the file descriptor for a file. The file will be created (if necessary) if "options" includes "w" or "a". In Batch GCOS, file code 'XX' can be directly accessed using a filename of "fc*XX". In TSS, a name of the form "fc*anything" always refers to a file in the AFT. If the filename has any other format, "fopen" tries to access it as a permfile. "options" points to a string containing one of
Several additional options can be specified by adding one or more letters to the possibilities listed above. All of the following options are unique to the GCOS-8 version of C and will not be portable to other implementations.
/* open file "uid/f" for writing binary */ f1 = fopen("uid/f", "wb"); /* open the string "str" for reading */ char *str; f2 = fopen(str, "rs"); /* open file with unique AFT name, remove when done */ f3 = fopen("x","w+btu");
When you specify "r+", you indicate that you want to read the file before you write to it. Thus the file must already exist.
When a file is opened with a "+" option, you may both read and write on it. However, you may not perform an output operation immediately after an input operation; you must perform an intervening "rewind" or "fseek". Similarly, you may not perform an input operation immediately after an output operation; you must perform an intervening "rewind" or "fseek".
The use of the 'b' or '+' options cause the file to be written in fixed-length, 318-word media 4 GFRC records. The length of the last record is adjusted to suit to actual length (in bytes) of the file. Since the file is not one of the standard text media codes, such a file cannot, in general, be read by other programs, unless they too are written in C and open the file with 'b' or '+' options.
When a file is opened for appending, it is impossible to overwrite the existing contents of the file. Every write operation automatically begins with a seek to the current end of the file. For example, if you use "fseek" or "fsetpos" to move into the middle of the file and then try a write operation, the library will automatically move back to the end of the file before the write takes place. This behavior is required by the ANSI standard for C.
expl c lib fclose
expl c lib fseek
expl c lib rewind
expl nsc lib _rblock
expl c lib _wblock
Copyright © 2000, Thinkage Ltd.