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

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

Added include files for global functions and variables.

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