본문 바로가기
C 언어

ftello

by SpeeDr00t 2016. 7. 9.
반응형

off_t

ftello(FILE *fp)


#include <stdio.h>
#include <errno.h>
#include "local.h"

/*
 * ftello: return current offset.
 */
off_t
ftello(FILE *fp)
{
	fpos_t pos;

	if (fp->_seek == NULL) {
		errno = ESPIPE;			/* historic practice */
		return ((off_t)-1);
	}

	/*
	 * Find offset of underlying I/O object, then
	 * adjust for buffered bytes.
	 */
	__sflush(fp);		/* may adjust seek offset on append stream */
	if (fp->_flags & __SOFF)
		pos = fp->_offset;
	else {
		pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
		if (pos == -1L)
			return (pos);
	}
	if (fp->_flags & __SRD) {
		/*
		 * Reading.  Any unread characters (including
		 * those from ungetc) cause the position to be
		 * smaller than that in the underlying object.
		 */
		pos -= fp->_r;
		if (HASUB(fp))
			pos -= fp->_ur;
	} else if (fp->_flags & __SWR && fp->_p != NULL) {
		/*
		 * Writing.  Any buffered characters cause the
		 * position to be greater than that in the
		 * underlying object.
		 */
		pos += fp->_p - fp->_bf._base;
	}
	return (pos);
}

/*
 * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches
 */
#if defined(__alpha__) && defined(__indr_reference)
__indr_reference(ftello, ftell);
#else
long
ftell(FILE *fp)
{
	long pos;

	pos = (long)ftello(fp);
	return(pos);
}
#endif
반응형

'C 언어' 카테고리의 다른 글

fileno  (0) 2016.07.09
feof  (0) 2016.07.09
mkstemp  (0) 2016.07.09
fgetln  (0) 2016.07.09
fflush  (0) 2016.07.09