home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_02
/
1002017a
< prev
next >
Wrap
Text File
|
1991-12-17
|
681b
|
35 lines
Listing 5 -- xfgpos.c
/* _Fgpos function -- UNIX version */
#include <errno.h>
#include "xstdio.h"
/* UNIX system call */
long _Lseek(int, long, int);
long _Fgpos(FILE *str, fpos_t *ptr)
{ /* get file position */
long loff = _Lseek(str->_Handle, 0L, 1);
if (loff == -1)
{ /* query failed */
errno = EFPOS;
return (EOF);
}
if (str-_Mode & _MWRITE)
loff += str->_Next - str->_Buf;
else if (str->_Mode & _MREAD)
loff -= str->_Nback
? str->_Rsave - str->_Next + str->_Nback
: str->_Rend - str->_Next;
if (ptr == NULL)
return (loff); /* ftell */
else
{ /* fgetpos */
ptr->_Off = loff;
return (0);
}
}