summaryrefslogtreecommitdiff
path: root/systems/knuth/local/bdemo_ext.c-sparc
blob: c0b78334dad37fea971b6b02afcc9fc2de65eb3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* External procedures for the binary demo program */

#include "h00vars.h"		/* defines Pascal I/O structure */

#define namelength 100          /* should agree with binarydemo.p */

movetobyte(filep,cnt)
	register struct iorec	*filep;
	int      	cnt;
{
	register FILE	*iop;	/* stdio-style FILE pointer */

	iop = filep->fbuf;
	fseek(iop,(long)cnt,0);
}

bool testeof(filep)
	register struct iorec	*filep;
{
	register char c;
	register FILE *iop; /* stdio-style FILE pointer */

	if (filep->funit & EOFF)
		return(TRUE);
	else { /* check to see if next is EOF */
		iop = filep->fbuf;
		c = getc(iop);
		if (c == EOF)
			return(TRUE);
		else {
			ungetc(c,iop);
			return(FALSE);
			}
		}
}

bool testreadaccess(fn)
	char  *fn;
{
	register char *p;

	fn[namelength-1] = ' ';
	p = fn;
	while (*p++ != ' ');
	p--;
	*p = '\0';
	if (access(fn,4)==0) {
	  *p = ' '; return(TRUE);}
	else {*p = ' '; return(FALSE);}
}

bool testwriteaccess(fn)
	char  *fn;
{
	register char *p;
	int f;

	fn[namelength-1] = ' ';
	p=fn;
	while (*p++ != ' ');
	p--;
	*p = '\0';
	f = creat(fn,0666);   /* we try to create a new file, because
				 simply testing write access with access(fn,2)
				 will fail when the file doesn't exist */
	*p = ' ';
	if (f >= 0) {close(f); return(TRUE);}
	else return(FALSE);
}

int flength(filep)
	register struct iorec	*filep;
{
	register FILE	*iop;	/* stdio-style FILE pointer */
	register long	pos;    /* current file position */
	register int	len;	/* the file length */

	iop = filep->fbuf;
	pos = ftell(iop);
	fseek(iop,0L,2);
	len = ftell(iop);
	fseek(iop,pos,0);
	return(len);
}