Fixed up the path spec and filename in the header blocks
[reactos.git] / reactos / lib / msvcrt / 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
4 #include <msvcrt/stdio.h>
5 #include <msvcrt/fcntl.h>
6 #include <msvcrt/io.h>
7 #include <msvcrt/errno.h>
8 #include <msvcrt/internal/file.h>
9
10
11 long ftell(FILE *f)
12 {
13 long tres;
14 int adjust=0;
15
16 if (!f)
17 {
18 __set_errno(EBADF);
19 return -1;
20 }
21
22 if (f->_cnt < 0)
23 f->_cnt = 0;
24 else if (f->_flag&(_IOWRT))
25 {
26 if (f->_base && (f->_flag&_IONBF)==0)
27 adjust = f->_ptr - f->_base;
28 }
29 else if (f->_flag&_IOREAD)
30 {
31 adjust = - f->_cnt;
32 }
33 else
34 return -1;
35
36 tres = lseek(fileno(f), 0L, SEEK_CUR);
37 if (tres<0)
38 return tres;
39 tres += adjust;
40
41 //f->_cnt = f->_bufsiz - tres;
42 //f->_ptr = f->_base + tres;
43
44 return tres;
45 }