2000-08-11 21:53:56 +00:00
|
|
|
/*
|
2014-06-30 09:10:35 +00:00
|
|
|
** ftell.c
|
|
|
|
**
|
|
|
|
** Christian Groessler, 2000-08-07
|
|
|
|
** Ullrich von Bassewitz, 2004-05-13
|
|
|
|
*/
|
2000-08-11 21:53:56 +00:00
|
|
|
|
|
|
|
|
2003-11-06 18:04:07 +00:00
|
|
|
|
2000-08-11 21:53:56 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2003-06-12 18:08:23 +00:00
|
|
|
#include <unistd.h>
|
2000-08-11 21:53:56 +00:00
|
|
|
#include "_file.h"
|
|
|
|
|
|
|
|
|
2003-11-06 18:04:07 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2003-11-06 18:04:07 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-13 21:54:01 +00:00
|
|
|
long __fastcall__ ftell (register FILE* f)
|
2000-08-11 21:53:56 +00:00
|
|
|
{
|
|
|
|
long pos;
|
|
|
|
|
|
|
|
/* Is the file open? */
|
|
|
|
if ((f->f_flags & _FOPEN) == 0) {
|
2010-06-03 20:46:08 +00:00
|
|
|
_seterrno (EINVAL); /* File not open */
|
2000-08-11 21:53:56 +00:00
|
|
|
return -1L;
|
|
|
|
}
|
|
|
|
|
2004-05-13 21:54:01 +00:00
|
|
|
/* Call the low level function */
|
|
|
|
pos = lseek (f->f_fd, 0L, SEEK_CUR);
|
|
|
|
|
|
|
|
/* If we didn't have an error, correct the return value in case we have
|
2014-06-30 09:10:35 +00:00
|
|
|
** a pushed back character.
|
|
|
|
*/
|
2004-05-13 21:54:01 +00:00
|
|
|
if (pos > 0 && (f->f_flags & _FPUSHBACK)) {
|
|
|
|
--pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -1 for error, comes from lseek() */
|
|
|
|
return pos;
|
2000-08-11 21:53:56 +00:00
|
|
|
}
|
|
|
|
|