]> git.sur5r.net Git - cc65/blob - libsrc/common/ftell.c
Changed most "backticks" (grave accents) into apostrophes.
[cc65] / libsrc / common / ftell.c
1 /*
2 ** ftell.c
3 **
4 ** Christian Groessler, 2000-08-07
5 ** Ullrich von Bassewitz, 2004-05-13
6 */
7
8
9
10 #include <stdio.h>
11 #include <errno.h>
12 #include <unistd.h>
13 #include "_file.h"
14
15
16
17 /*****************************************************************************/
18 /*                                   Code                                    */
19 /*****************************************************************************/
20
21
22
23 long __fastcall__ ftell (register FILE* f)
24 {
25     long pos;
26
27     /* Is the file open? */
28     if ((f->f_flags & _FOPEN) == 0) {
29         _seterrno (EINVAL);                /* File not open */
30         return -1L;
31     }
32
33     /* Call the low level function */
34     pos = lseek (f->f_fd, 0L, SEEK_CUR);
35
36     /* If we didn't have an error, correct the return value in case we have
37     ** a pushed back character.
38     */
39     if (pos > 0 && (f->f_flags & _FPUSHBACK)) {
40         --pos;
41     }
42
43     /* -1 for error, comes from lseek() */
44     return pos;
45 }
46