-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacorn.c
116 lines (103 loc) · 2.22 KB
/
acorn.c
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Operating System specific function (Acorn)
*
* $Header: acorn.c 1.1 93/03/05 $
* $Log: acorn.c,v $
* Revision 1.1 93/03/05 14:34:04 arb
* Initial revision
*
*/
#include "spark.h"
#include "date.h"
#include "kernel.h"
#include "swis.h"
/*
* return the length of a file
*/
Word
filesize(char *pathname)
{
int rc;
_kernel_osfile_block osblock;
rc = _kernel_osfile(17, pathname, &osblock);
if (rc == _kernel_ERROR)
return (0);
/* Bit 1 is set if a file, bit 2 if a directory, both if image file */
if (rc & 1)
return ((Word) osblock.start);
else
return (0);
}
/*
* test for the existance of a file or directory
*/
Ftype
exist(char *pathname)
{
int rc;
_kernel_osfile_block osblock;
rc = _kernel_osfile(17, pathname, &osblock);
if (rc == _kernel_ERROR)
return (NOEXIST); /* assumes error was because file
doesn't exist... could be wrong! */
if (rc & 1)
return (ISFILE); /* might not be a regular file... (eg. image) */
if (rc & 2)
return (ISDIR);
else
return (NOEXIST);
}
/*
* make a directory
*/
int
makedir(char *pathname)
{
int rc;
_kernel_osfile_block osblock;
osblock.start = 0; /* Default number of entries */
rc = _kernel_osfile(8, pathname, &osblock);
if (rc == _kernel_ERROR)
return (-1); /* Should set errno */
else
return (0);
}
/*
* stamp a file with date and time
*/
int
filestamp(Header *header, char *filename)
{
int rc;
_kernel_osfile_block osblock;
if ((header->load & (Word) 0xfff00000) != (Word) 0xfff00000)
return (0); /* not a timestamp */
osblock.load = header->load;
osblock.exec = header->exec;
osblock.end = header->attr;
rc = _kernel_osfile(1, filename, &osblock);
if (rc == _kernel_ERROR)
return (-1);
else
return (0);
}
/*
* read byte from stream (only one line from stdin supported)
*/
int
read(int fd, void *buffer, int len)
{
_kernel_swi_regs regs;
int carry;
if (fd != 0) /* Only stdin, sorry! */
return (0);
regs.r[0] = (int) buffer;
regs.r[1] = len;
regs.r[2] = 1; /* Low/high values to store */
regs.r[3] = 255;
if (_kernel_swi_c(OS_ReadLine, ®s, ®s, &carry))
return (-1); /* Error occurred */
if (carry)
return (-1); /* Escape pressed */
return (regs.r[1]); /* Return number of bytes read */
}