|
|
1.1 ! root 1: /* Copyright AT&T Bell Laboratories, 1993 */ ! 2: #include <stdio.h> ! 3: ! 4: unsigned ! 5: fread(void *ptr, unsigned size, unsigned count, FILE *iop) ! 6: { ! 7: int l, c; ! 8: unsigned char *s = ptr; ! 9: unsigned char *t; ! 10: unsigned long n = (unsigned long)count*size; ! 11: for(;;) { ! 12: l = iop->_cnt; ! 13: if(l > n) l = n; ! 14: t = iop->_ptr; ! 15: iop->_cnt -= l; ! 16: iop->_ptr += l; ! 17: n -= l; ! 18: while(--l >= 0) ! 19: *s++ = *t++; ! 20: if(n == 0) ! 21: return count; ! 22: c = getc(iop); ! 23: if(c == EOF) ! 24: return count - (n+size-1)/size; ! 25: *s++ = c; ! 26: n--; ! 27: } ! 28: } ! 29: ! 30: unsigned ! 31: fwrite(const void *ptr, unsigned size, unsigned count, FILE *iop) ! 32: { ! 33: int l; ! 34: unsigned char *s = ptr; ! 35: unsigned char *t; ! 36: unsigned long n = (unsigned long)count*size; ! 37: for(;;) { ! 38: l = iop->_cnt; ! 39: if(l > n) l = n; ! 40: t = iop->_ptr; ! 41: iop->_cnt -= l; ! 42: iop->_ptr += l; ! 43: n -= l; ! 44: while(--l >= 0) ! 45: *t++ = *s++; ! 46: if(n == 0) ! 47: return count; ! 48: if(putc(*s++, iop) == EOF) ! 49: return count - (n+size-1)/size; ! 50: n--; ! 51: } ! 52: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.