%READ (D3/Unix)

%READ (D3/Unix)


%RDHEX Index Level %READ (AP/DOS)
Syntax n = %READ( file.descriptor, variable, size )
Category BASIC
Type C Function
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.
Options
See Also %MALLOC %RDHEX CFUNCTION c function %DUP %CREAT %TTYNAME %OPEN %BIND %LISTEN %LSEEK (D3/Unix)
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
Warnings
Compatibility D3/Unix
%RDHEX Index Level %READ (AP/DOS)