1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#include "sfhdr.h"
1N/A
1N/A/* Tell the current location in a given stream
1N/A**
1N/A** Written by Kiem-Phong Vo.
1N/A*/
1N/A
1N/A#if __STD_C
1N/ASfoff_t sftell(Sfio_t* f)
1N/A#else
1N/ASfoff_t sftell(f)
1N/ASfio_t *f;
1N/A#endif
1N/A{
1N/A reg int mode;
1N/A Sfoff_t p;
1N/A SFMTXDECL(f);
1N/A
1N/A SFMTXENTER(f, (Sfoff_t)(-1));
1N/A
1N/A /* set the stream to the right mode */
1N/A if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)
1N/A SFMTXRETURN(f, (Sfoff_t)(-1));
1N/A
1N/A /* throw away ungetc data */
1N/A if(f->disc == _Sfudisc)
1N/A (void)sfclose((*_Sfstack)(f,NIL(Sfio_t*)));
1N/A
1N/A if(f->flags&SF_STRING)
1N/A SFMTXRETURN(f, (Sfoff_t)(f->next-f->data));
1N/A
1N/A /* let sfseek() handle the hard case */
1N/A if(f->extent >= 0 && (f->flags&(SF_SHARE|SF_APPENDWR)) )
1N/A p = sfseek(f,(Sfoff_t)0,SEEK_CUR);
1N/A else p = f->here + ((f->mode&SF_WRITE) ? f->next-f->data : f->next-f->endb);
1N/A
1N/A SFMTXRETURN(f,p);
1N/A}