SPL to HP C/XL Migration Guide (30231-90001)
9- 5
| read(
fildes
,
buf
,
nbyte
) Read fixed-length binary records from file |
|
fildes
|
| remove(
filename
) Purge file
filename
|
| rename(
oldname
,
newname
) Rename file |
| rewind(
stream
) Reset byte position to beginning of file |
|
stream
|
| scanf(
format
[,
item
][...]) Read from stdin; convert to internal
item
|
| setbuf(
stream
,
buffer
) Define buffer for file
stream
|
| setvbuf(
stream
,
buffer
,
type
,
size
) Define buffer for file
stream
|
-------------------------------------------------------------------------------------------
| sprintf(
string
,
format
[,
item
][...]) Convert from internal
item
; write to
string
|
| sscanf(
string
,
format
[,
item
][...]) Read from
string
; convert to internal
item
|
| tmpfile() Open unnamed tempfile |
| tmpnam(
string
) Create temp
filename
in
string
|
| ungetc(
c
,
stream
) Push back character
c
to input file
stream
|
| unlink(
filename
) Purge file
filename
|
| write(
fildes
,
buf
,
nbyte
) Write fixed-length binary records to file |
|
fildes
|
-------------------------------------------------------------------------------------------
Opening a New Disk File
SPL uses the MPE V intrinsic FOPEN to create and open disk files. FOPEN
allows SPL to have complete control over the definition of a new file.
It returns a file number,
filenum
, which is used to identify the access
to this file for subsequent I/O operations by other intrinsics, such as
FREAD and FWRITE. If an error occurs, FOPEN returns zero and sets the
condition code to CCL.
In HP C/XL, a file may be created and opened with the library functions
open and fopen or with the MPE XL intrinsics FOPEN and HPFOPEN.
The most preferred and portable is HP C/XL fopen, which returns a
stream
pointer that is used by all of the HP C/XL standard data formatting and
character transfer functions, such as fscanf and fprintf. If fopen
fails, it returns a null pointer.
If you need the HP C/XL binary read and write functions, or more file
creation control, the open function provides more system-specific
capabilities, which make it less portable. open returns
fildes
, a 32-
bit int file descriptor, which may be used to obtain both a
stream
pointer and a
filenum
file number.
Reading a File in Sequential Order
SPL uses the FREAD intrinsic to read all or part of a record in a
sequential file with fixed- or variable-length records. A logical
record pointer points to the next record to be read. When any part of
a record is read, the pointer advances to the next record.
HP C/XL has several ways to read records. The fgets function is probably
the closest to the SPL action: a requested number of bytes or all the
characters up to the end of the record are read into a buffer. If the
end of record was reached, HP C/XL marks it by appending a '\n'
(linefeed) character to the record data in the buffer. In any case, HP
C/XL appends a '\0' (NUL) character to mark the end of the data in the
buffer.