scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <stdio.h>
 2
 3#include "../syscall.h"
 4
 5#undef ftell
 6
 7long
 8ftell(FILE *fp)
 9{
10	long off;
11	unsigned char *p;
12
13	if (fp->flags & _IOERR)
14		return EOF;
15
16	if ((off = _lseek(fp->fd, 0, SEEK_CUR)) < 0) {
17		fp->flags |= _IOERR;
18		return EOF;
19	}
20
21	if (fp->flags & _IOREAD)
22		return off - (fp->wp - fp->rp);
23
24	if (fp->flags & _IOWRITE) {
25		p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;
26		return off + (p - fp->buf);
27	}
28	return off;
29}