home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
stdio
/
c
/
fpos
< prev
next >
Wrap
Text File
|
1994-03-08
|
1KB
|
92 lines
static char sccs_id[] = "@(#) fpos.c 1.2 " __DATE__ " HJR";
/* fpos.c (c) Copyright 1990 H.Rogers */
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
extern long lseek (int, long, int);
__STDIOLIB__
int
fgetpos (register FILE * f, register fpos_t * p)
{
long i;
i = ftell (f);
if (i < 0)
return ((int) i);
*p = (fpos_t) i;
return (0);
}
int
fsetpos (register FILE * f, register const fpos_t * p)
{
return (fseek (f, (long) (*p), 0));
}
int
fseek (register FILE * f, long p, int w)
{
long c;
if (!fisopen (f))
return (-1);
c = ftell (f);
fflush (f);
if (f->flag & _IOERR)
return (-1);
f->flag &= ~_IOEOF;
if (w == SEEK_SET)
{
if ((c = lseek (f->fd, p, 0)) < 0)
goto err;
}
else if (w == SEEK_CUR)
{
if ((c = lseek (f->fd, p + c, 0)) < 0)
goto err;
}
else if (w == SEEK_END)
{
if ((c = lseek (f->fd, p, 2)) < 0)
goto err;
}
else
return (-1);
f->pos = (fpos_t) c;
return (0);
{
err:
f->flag |= _IOERR;
return (-1);
}
}
long
ftell (register FILE * f)
{
if (!fisopen (f))
return (-1);
if (f->i_base)
return (f->pos - (long) f->i_cnt);
else if (f->o_base)
return (f->pos + (long) (f->o_ptr - f->o_base));
else
return (f->pos);
}
void
rewind (register FILE * f)
{
fseek (f, 0L, 0);
clearerr (f);
}