source: buchla-68k/libcio/ftell.c@ 9519422

Last change on this file since 9519422 was 7258c6a, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Use standard integer types.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 =============================================================================
3 ftell.c -- return current file position
4 Version 7 -- 1987-10-28 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGIT 0
9
10#include "biosdefs.h"
11#include "stdio.h"
12#include "io.h"
13#include "stddefs.h"
14
15#if DEBUGIT
16extern short fsdebug;
17#endif
18
19extern int16_t _filecl(struct fcb *fp);
20
21/*
22 =============================================================================
23 ftell(fp) -- return the current position of file 'fp'.
24 =============================================================================
25*/
26
27int32_t ftell(FILE *fp)
28{
29 register struct fcb *fcp;
30 register struct channel *chp;
31 register int32_t dpos, pos, diff;
32
33 if (fp EQ (FILE *)0L) { /* see if we point at a FILE */
34
35#if DEBUGIT
36 if (fsdebug)
37 printf("ftell($%08.8lX): ERROR - null FILE pointer\n", fp);
38#endif
39
40 return(0L);
41 }
42
43 if (!fp->_flags & _BUSY) { /* see if it's open */
44
45#if DEBUGIT
46 if (fsdebug)
47 printf("ftell($%08.8lX): ERROR - FILE not open\n", fp);
48#endif
49
50 return(0L);
51 }
52
53 chp = &chantab[fp->_unit]; /* point at the channel */
54
55 if (chp->c_close NE _filecl) { /* see if it's seekable */
56
57#if DEBUGIT
58 if (fsdebug)
59 printf("ftell($%08.8lX): ERROR - FILE device not seekable\n",
60 fp);
61#endif
62
63 return(0L);
64 }
65
66 fcp = chp->c_arg; /* point at the FCB */
67
68 dpos = fcp->offset + (fcp->curlsn << FILESHFT);
69
70 if (fp->_flags & _DIRTY) /* adjust for the buffering */
71 pos = dpos + (diff = ((int32_t)fp->_bp - (int32_t)fp->_buff));
72 else if (fp->_bp)
73 pos = dpos - (diff = ((int32_t)fp->_bend - (int32_t)fp->_bp));
74 else
75 pos = dpos;
76
77#if DEBUGIT
78 if (fsdebug) {
79
80 printf("ftell($%08.8lX): flags=$%04.4X, buff=$%08.8lX, bp=$%08.8lX, bend=$%08.8lX\n",
81 fp, fp->_flags, fp->_buff, fp->_bp, fp->_bend);
82 printf("ftell($%08.8lX): fcp=$%08.8lX, pos=%ld, dpos=%ld, diff=%ld\n",
83 fp, fcp, pos, dpos, diff);
84 printf("ftell($%08.8lX): curlsn=%ld, offset=%u\n",
85 fp, fcp->curlsn, fcp->offset);
86
87 if ((fp->_flags & _DIRTY) AND (fp->_bp EQ NULL))
88 printf("ftell($%08.8lX): ERROR - file is DIRTY and bp is NULL\n",
89 fp);
90 }
91#endif
92
93 return(pos);
94}
Note: See TracBrowser for help on using the repository browser.