:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / stdio / ftell.c
1 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 //#include <crtdll/stubs.h>
4 #include <crtdll/stdio.h>
5 //#include <crtdll/unistd.h>
6 #include <crtdll/internal/file.h>
7 #include <crtdll/fcntl.h>
8 #include <crtdll/io.h>
9 #include <errno.h>
10
11
12 long
13 ftell(FILE *f)
14 {
15   long tres;
16   int adjust=0;
17
18   if (!f) 
19   {
20     __set_errno(EBADF);
21     return -1;
22   }
23
24   if (f->_cnt < 0)
25     f->_cnt = 0;
26  
27   else if (f->_flag&_IOREAD)
28   {
29     adjust = - f->_cnt;
30   }
31   else if (f->_flag&(_IOWRT))
32   {
33     if (f->_base && (f->_flag&_IONBF)==0)
34       adjust = f->_ptr - f->_base;
35   }
36
37   else
38     return -1;
39   tres = lseek(fileno(f), 0L, SEEK_CUR);
40   if (tres<0)
41     return tres;
42   tres += adjust;
43   
44   //f->_cnt = f->_bufsiz - tres;
45   //f->_ptr = f->_base + tres;
46   return tres;
47 }