home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_02 / 1002018a < prev    next >
Text File  |  1991-12-17  |  1KB  |  46 lines

  1.  
  2. Listing 6 -- the file xfspos.c
  3.  
  4. /* _Fspos function -- UNIX version */
  5. #include <errno.h>
  6. #include "xstdio.h"
  7.  
  8.         /* UNIX system call */
  9. long _Lseek(int, long, int);
  10.  
  11. int _Fspos(FILE *str, const fpos_t *ptr, long loff, int way)
  12.     {   /* position a file */
  13.     if (fflush(str))
  14.         {   /* write error */
  15.         errno = EFPOS;
  16.         return (EOF);
  17.         }
  18.     if (ptr)
  19.         loff += ((fpos_t *)ptr)->_Off; /* fsetpos */
  20.     if (way == SEEK_CUR && str->_Mode & _MREAD)
  21.         loff -= str->_Nback
  22.             ? str->_Rsave - str->_Next + str->_Nback
  23.             : str->_Rend - str->_Next;
  24.     if (way == SEEK_CUR && loff != 0
  25.         || way != SEEK_SET || loff != -1)
  26.         loff = _Lseek(str->_Handle, loff, way);
  27.     if (loff == -1)
  28.         {   /* request failed */
  29.         errno = EFPOS;
  30.         return (EOF);
  31.         }
  32.     else
  33.         {   /* success */
  34.         if (str->_Mode & (_MREAD|_MWRITE))
  35.             {   /* empty buffer */
  36.             str->_Next = str->_Buf;
  37.             str->_Rend = str->_Buf;
  38.             str->_Wend = str->_Buf;
  39.             str->_Nback = 0;
  40.             }
  41.         str->_Mode &= ~(_MEOF|_MREAD|_MWRITE);
  42.         return (0);
  43.         }
  44.     }
  45.  
  46.