1989-05-30 13:34:25 +00:00
|
|
|
/*
|
|
|
|
* ftell.c - obtain the value of the file-position indicator of a stream
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2007-04-21 23:18:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2019-06-15 11:07:10 +00:00
|
|
|
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE
|
2018-06-23 16:54:40 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
long ftell(FILE* stream)
|
1989-05-30 13:34:25 +00:00
|
|
|
{
|
|
|
|
long result;
|
1989-06-26 10:37:05 +00:00
|
|
|
int adjust = 0;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
if (io_testflag(stream, _IOREADING))
|
1989-05-30 13:34:25 +00:00
|
|
|
adjust = -stream->_count;
|
2018-06-21 20:33:47 +00:00
|
|
|
else if (io_testflag(stream, _IOWRITING)
|
|
|
|
&& stream->_buf
|
|
|
|
&& !io_testflag(stream, _IONBF))
|
1989-05-30 13:34:25 +00:00
|
|
|
adjust = stream->_ptr - stream->_buf;
|
2018-06-21 20:33:47 +00:00
|
|
|
else
|
|
|
|
adjust = 0;
|
1989-12-18 15:04:14 +00:00
|
|
|
|
2007-04-21 23:18:14 +00:00
|
|
|
result = lseek(fileno(stream), 0, SEEK_CUR);
|
1989-05-30 13:34:25 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
if (result == -1)
|
1989-05-30 13:34:25 +00:00
|
|
|
return result;
|
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
result += (long)adjust;
|
1989-05-30 13:34:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-06-23 16:54:40 +00:00
|
|
|
|
|
|
|
#endif
|