basic.%read C Function/BASIC Program

basic.%read

Command basic.%read C Function/BASIC Program
Applicable release versions: AP/Unix
Category BASIC Program (486)
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.
Syntax n=%read(file.descriptor, variable, size)
Options
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
Purpose
Related basic.%malloc
basic.%rdhex
basic.cfunction
basic.cfunc
basic.%dup
basic.%creat
basic.%ttyname
basic.%open
basic.%bind
basic.%listen
basic.%lseek