source: buchla-68k/libcio/fsize.c@ 0580615

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

Point of no return.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 =============================================================================
3 fsize.c -- file size and disk capacity functions
4 Version 1 -- 1987-10-29 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stdio.h"
9#include "biosdefs.h"
10#include "io.h"
11#include "stddefs.h"
12
13extern unsigned _gtcl12(char *fat, unsigned cl);
14extern int _opnvol(void);
15extern int _filecl(struct fcb *fp);
16
17extern unsigned _thefat[];
18
19extern struct bpb *_thebpb;
20
21/*
22 =============================================================================
23 fsize() -- return the current size of an open stream file
24
25 how = 0: in bytes, 1: in allocated clusters
26 =============================================================================
27*/
28
29long fsize(FILE *fp, short how)
30{
31 register struct channel *chp;
32 register struct fcb *fcp;
33
34 if (fp EQ (FILE *)0L)
35 return(-1L);
36
37 if (fp->_flags & _BUSY) {
38
39 chp = &chantab[fp->_unit];
40
41 if (chp->c_close NE _filecl)
42 return(-1L);
43
44 fcp = chp->c_arg;
45
46 if (fcp->modefl & FC_OPN) {
47
48 if (how)
49 return(fcp->asects);
50 else
51 return(fcp->curlen);
52
53 } else
54 return(-1L);
55
56 } else
57 return(-1L);
58}
59
60/*
61
62*/
63
64/*
65 =============================================================================
66 dspace() -- return disk capacity or usage
67
68 which = 0: capcity, 1: usage
69 =============================================================================
70*/
71
72short dspace(short which)
73{
74 register short maxcl, clcount, nc;
75
76 if (_opnvol())
77 return(-1L);
78
79 maxcl = _thebpb->numcl;
80
81 if (which) {
82
83 clcount = 0;
84
85 for (nc = 2; nc < maxcl; nc++)
86 if (0 EQ _gtcl12(_thefat, nc))
87 ++clcount;
88
89 return(clcount);
90
91 } else {
92
93 return(maxcl);
94 }
95}
Note: See TracBrowser for help on using the repository browser.