basic.%read
Reads from a Unix file.
Syntax
n=%read(file.descriptor, variable, size)
Description
reads the number of bytes designated in 'size' into the 'variable', from the file specified by 'file.descriptor' returned by a previous call to '%open()', '%creat()' or 'dup()'.
A string of a size at least equal to 'size' must have been assigned to 'variable' before the call by either an explicit assignment (eg buffer=space(1000)) or by the 'char' reserve statement, or else the data is truncated.
This function returns the number of bytes actually read. If less than 'size' bytes are returned, the content of the string beyond is undefined, as is usual in C. No data translation occurs. If the data read in variable contains Segment Marks (x'ff'), results are unpredictable. Use '%malloc()' to obtain a Unix memory in which to read binary data.
Example
item=''
char buffer[10000] ;* reserve buffer space
loop while true do
n=%read(fd, buffer, 10000)
if n=-1 then
print 'Error ':system(0)
stop
end else
if n<10000 then
* The whole file has been read.
item=item:buffer[1,n]
convert char(10) to char(254) in item
write item on itemname
stop
end else
* Some more to read
item=item:buffer
end
end
repeat
See Also
User Comments
What do you think?
Share your experience or ask a question by using the form below.
Login to leave your comments.
