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

Last change on this file since 572daa7 was 8973acd, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in libcio.

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