1: /*	@(#)fseek.c	2.1	SCCS id keyword	*/
   2: /*
   3:  * Seek for standard library.  Coordinates with buffering.
   4:  */
   5: 
   6: #include    <stdio.h>
   7: 
   8: long lseek();
   9: 
  10: fseek(iop, offset, ptrname)
  11:     register FILE *iop;
  12:     long offset;
  13: {
  14:     register int c;
  15:     long p;
  16: 
  17:     iop->_flag &= ~_IOEOF;
  18:     if (iop->_flag & _IOREAD) {
  19:         if (ptrname < 2 && iop->_base && !(iop->_flag&_IONBF)) {
  20:             c = iop->_cnt;
  21:             p = offset;
  22:             if (ptrname == 0)
  23:                 p += c - lseek(fileno(iop), 0L, 1);
  24:             else
  25:                 offset -= c;
  26:             if (!(iop->_flag&_IORW) && c > 0 && p <= c
  27:                 && p >= iop->_base - iop->_ptr){
  28:                 iop->_ptr += (int) p;
  29:                 iop->_cnt -= (int) p;
  30:                 return(0);
  31:             }
  32:         }
  33:         if (iop->_flag & _IORW) {
  34:             iop->_ptr = iop->_base;
  35:             iop->_flag &= ~_IOREAD;
  36:         }
  37:         p = lseek(fileno(iop), offset, ptrname);
  38:         iop->_cnt = 0;
  39:     } else if(iop->_flag & (_IOWRT|_IORW)) {
  40:         fflush(iop);
  41:         if (iop->_flag & _IORW) {
  42:             iop->_cnt = 0;
  43:             iop->_flag &= ~_IOWRT;
  44:             iop->_ptr = iop->_base;
  45:         }
  46:         p = lseek(fileno(iop), offset, ptrname);
  47:     }
  48:     return(p==-1? -1: 0);
  49: }

Defined functions

fseek defined in line 10; used 142 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 882
Valid CSS Valid XHTML 1.0 Strict