home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  767 b   |  42 lines

  1. #include "lib.h"
  2.  
  3. #ifndef __MSHORT__
  4. asm(".text; .even; .globl _read; _read:"); /* dept of dirty tricks */
  5. #endif
  6.  
  7. PUBLIC long lread(fd, buffer, nbytes)
  8. int fd;
  9. _VOIDSTAR buffer;
  10. long nbytes;
  11. {
  12.   int n;
  13.   long tot, left;
  14.  
  15.   if(nbytes <= 32767)
  16.   {
  17.     n = callm1(FS, READ, fd, (int)nbytes, 0, buffer, NIL_PTR, NIL_PTR);
  18.     return((long)n);
  19.   }
  20.   for( tot = 0L, left = nbytes; left > 0L; )
  21.   {
  22.     n = (left > 32767) ? 32767 : (int)left;
  23.         if((n = callm1(FS, READ, fd, n, 0, buffer, NIL_PTR, NIL_PTR)) < 0)
  24.         return(n);
  25.     if(n == 0) return(tot);
  26.     tot += n;
  27.     left -= n;
  28.     (char *)buffer += n;
  29.   }
  30.   return(tot);
  31. }
  32.  
  33. #ifdef __MSHORT__
  34. PUBLIC int read(fd, buffer, nbytes)
  35. int fd;
  36. _VOIDSTAR buffer;
  37. int nbytes;
  38. {
  39.     return (int)lread(fd, buffer, (long)nbytes);
  40. }
  41. #endif
  42.