1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * reads(f,i) - read i characters on file f.
   5:  */
   6: Xreads(nargs, arg2, arg1, arg0)
   7: int nargs;
   8: struct descrip arg2, arg1, arg0;
   9:    {
  10:    register int cnt;
  11:    int status;
  12:    FILE *f;
  13: 
  14:    /*
  15:     * f defaults to &input and i defaults to 1 (character).
  16:     */
  17:    deffile(&arg1, &input);
  18:    defshort(&arg2, 1);
  19: 
  20:    /*
  21:     * Get a pointer to the file and be sure that it's open for reading.
  22:     */
  23:    f = BLKLOC(arg1)->file.fd;
  24:    status = BLKLOC(arg1)->file.status;
  25:    if ((status & FS_READ) == 0)
  26:       runerr(212, &arg1);
  27: 
  28:    /*
  29:     * Be sure that a positive number of bytes is to be read.
  30:     */
  31:    if ((cnt = INTVAL(arg2)) <= 0)
  32:       runerr(205, &arg2);
  33: 
  34:    /*
  35:     * Ensure that enough space for the string exists and read it directly
  36:     *  into the string space.  (By reading directly into the string space,
  37:     *  no arbitrary restrictions are placed on the size of the string that
  38:     *  can be read.)  Make arg0 a descriptor for the string and return it.
  39:     */
  40:    sneed(cnt);
  41:    if (sfree + cnt > estrings)
  42:       runerr(302, NULL);
  43:    STRLOC(arg0) = sfree;
  44:    if ((cnt = fread(STRLOC(arg0), sizeof(char), cnt, f)) <= 0)
  45:       fail();
  46:    STRLEN(arg0) = cnt;
  47:    sfree += cnt;
  48:    }
  49: 
  50: Procblock(reads,2)

Defined functions

Xreads defined in line 6; never used
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 767
Valid CSS Valid XHTML 1.0 Strict