Add missing break
[debian-nspark.git] / acorn.c
blob5271f3a7cf590525d9cd5addabda1128bf59187f
2 /*
3 * Operating System specific function (Acorn)
5 * $Header: acorn.c 1.1 93/03/05 $
6 * $Log: acorn.c,v $
7 * Revision 1.1 93/03/05 14:34:04 arb
8 * Initial revision
9 *
12 #include "spark.h"
13 #include "date.h"
14 #include "kernel.h"
15 #include "swis.h"
18 * return the length of a file
20 Word
21 filesize(char *pathname)
23 int rc;
24 _kernel_osfile_block osblock;
26 rc = _kernel_osfile(17, pathname, &osblock);
27 if (rc == _kernel_ERROR)
28 return (0);
29 /* Bit 1 is set if a file, bit 2 if a directory, both if image file */
30 if (rc & 1)
31 return ((Word) osblock.start);
32 else
33 return (0);
37 * test for the existance of a file or directory
39 Ftype
40 exist(char *pathname)
42 int rc;
43 _kernel_osfile_block osblock;
45 rc = _kernel_osfile(17, pathname, &osblock);
46 if (rc == _kernel_ERROR)
47 return (NOEXIST); /* assumes error was because file
48 doesn't exist... could be wrong! */
49 if (rc & 1)
50 return (ISFILE); /* might not be a regular file... (eg. image) */
51 if (rc & 2)
52 return (ISDIR);
53 else
54 return (NOEXIST);
58 * make a directory
60 int
61 makedir(char *pathname)
63 int rc;
64 _kernel_osfile_block osblock;
66 osblock.start = 0; /* Default number of entries */
67 rc = _kernel_osfile(8, pathname, &osblock);
68 if (rc == _kernel_ERROR)
69 return (-1); /* Should set errno */
70 else
71 return (0);
75 * stamp a file with date and time
77 int
78 filestamp(Header *header, char *filename)
80 int rc;
81 _kernel_osfile_block osblock;
83 if ((header->load & (Word) 0xfff00000) != (Word) 0xfff00000)
84 return (0); /* not a timestamp */
86 osblock.load = header->load;
87 osblock.exec = header->exec;
88 osblock.end = header->attr;
89 rc = _kernel_osfile(1, filename, &osblock);
90 if (rc == _kernel_ERROR)
91 return (-1);
92 else
93 return (0);
97 * read byte from stream (only one line from stdin supported)
99 int
100 read(int fd, void *buffer, int len)
102 _kernel_swi_regs regs;
103 int carry;
105 if (fd != 0) /* Only stdin, sorry! */
106 return (0);
107 regs.r[0] = (int) buffer;
108 regs.r[1] = len;
109 regs.r[2] = 1; /* Low/high values to store */
110 regs.r[3] = 255;
111 if (_kernel_swi_c(OS_ReadLine, &regs, &regs, &carry))
112 return (-1); /* Error occurred */
113 if (carry)
114 return (-1); /* Escape pressed */
115 return (regs.r[1]); /* Return number of bytes read */