source: buchla-68k/orig/IOLIB/FTELL.C@ 6099cac

Last change on this file since 6099cac was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.2 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 int _filecl();
20
21/*
22 =============================================================================
23 ftell(fp) -- return the current position of file 'fp'.
24 =============================================================================
25*/
26
27long
28ftell(fp)
29register FILE *fp;
30{
31 register struct fcb *fcp;
32 register struct channel *chp;
33 register long dpos, pos, diff;
34
35 if (fp EQ (FILE *)0L) { /* see if we point at a FILE */
36
37#if DEBUGIT
38 if (fsdebug)
39 printf("ftell($%08.8lX): ERROR - null FILE pointer\n", fp);
40#endif
41
42 return(0L);
43 }
44
45 if (!fp->_flags & _BUSY) { /* see if it's open */
46
47#if DEBUGIT
48 if (fsdebug)
49 printf("ftell($%08.8lX): ERROR - FILE not open\n", fp);
50#endif
51
52 return(0L);
53 }
54
55 chp = &chantab[fp->_unit]; /* point at the channel */
56
57 if (chp->c_close NE _filecl) { /* see if it's seekable */
58
59#if DEBUGIT
60 if (fsdebug)
61 printf("ftell($%08.8lX): ERROR - FILE device not seekable\n",
62 fp);
63#endif
64
65 return(0L);
66 }
67
68 fcp = chp->c_arg; /* point at the FCB */
69
70 dpos = fcp->offset + (fcp->curlsn << FILESHFT);
71
72 if (fp->_flags & _DIRTY) /* adjust for the buffering */
73 pos = dpos + (diff = ((long)fp->_bp - (long)fp->_buff));
74 else if (fp->_bp)
75 pos = dpos - (diff = ((long)fp->_bend - (long)fp->_bp));
76 else
77 pos = dpos;
78
79#if DEBUGIT
80 if (fsdebug) {
81
82 printf("ftell($%08.8lX): flags=$%04.4X, buff=$%08.8lX, bp=$%08.8lX, bend=$%08.8lX\n",
83 fp, fp->_flags, fp->_buff, fp->_bp, fp->_bend);
84 printf("ftell($%08.8lX): fcp=$%08.8lX, pos=%ld, dpos=%ld, diff=%ld\n",
85 fp, fcp, pos, dpos, diff);
86 printf("ftell($%08.8lX): curlsn=%ld, offset=%u\n",
87 fp, fcp->curlsn, fcp->offset);
88
89 if ((fp->_flags & _DIRTY) AND (fp->_bp EQ NULL))
90 printf("ftell($%08.8lX): ERROR - file is DIRTY and bp is NULL\n",
91 fp);
92 }
93#endif
94
95 return(pos);
96}
Note: See TracBrowser for help on using the repository browser.