31 lines
		
	
	
	
		
			588 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
	
		
			588 B
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * ftell.c - obtain the value of the file-position indicator of a stream
 | 
						|
 */
 | 
						|
/* $Id$ */
 | 
						|
 | 
						|
#include <stdlib.h>
 | 
						|
#include <stdio.h>
 | 
						|
#include <unistd.h>
 | 
						|
#include	"loc_incl.h"
 | 
						|
 | 
						|
long ftell(FILE *stream)
 | 
						|
{
 | 
						|
	long result;
 | 
						|
	int adjust = 0;
 | 
						|
 | 
						|
	if (io_testflag(stream,_IOREADING))
 | 
						|
		adjust = -stream->_count;
 | 
						|
	else if (io_testflag(stream,_IOWRITING)
 | 
						|
		    && stream->_buf
 | 
						|
		    && !io_testflag(stream,_IONBF))
 | 
						|
		adjust = stream->_ptr - stream->_buf;
 | 
						|
	else adjust = 0;
 | 
						|
 | 
						|
	result = lseek(fileno(stream), 0, SEEK_CUR);
 | 
						|
 | 
						|
	if ( result == -1 )
 | 
						|
		return result;
 | 
						|
 | 
						|
	result += (long) adjust;
 | 
						|
	return result;
 | 
						|
}
 |