fileio.c revision 1.1 1 1.1 christos #include <stdio.h>
2 1.1 christos #include <stdlib.h>
3 1.1 christos #include <string.h>
4 1.1 christos #include <sys/errno.h>
5 1.1 christos #include <sys/types.h>
6 1.1 christos #include <sys/fcntl.h>
7 1.1 christos #include <sys/stat.h>
8 1.1 christos #include <sys/time.h>
9 1.1 christos #include <errno.h>
10 1.1 christos #include <sys/wait.h>
11 1.1 christos #include <unistd.h>
12 1.1 christos /* TESTS :
13 1.1 christos * - open(const char *pathname, int flags, mode_t mode);
14 1.1 christos 1) Attempt to create file that already exists - EEXIST
15 1.1 christos 2) Attempt to open a directory for writing - EISDIR
16 1.1 christos 3) Pathname does not exist - ENOENT
17 1.1 christos 4) Open for write but no write permission - EACCES
18 1.1 christos
19 1.1 christos read(int fd, void *buf, size_t count);
20 1.1 christos 1) Read using invalid file descriptor - EBADF
21 1.1 christos
22 1.1 christos write(int fd, const void *buf, size_t count);
23 1.1 christos 1) Write using invalid file descriptor - EBADF
24 1.1 christos 2) Attempt to write to read-only file - EBADF
25 1.1 christos
26 1.1 christos lseek(int fildes, off_t offset, int whence);
27 1.1 christos 1) Seeking on an invalid file descriptor - EBADF
28 1.1 christos 2) Invalid "whence" (3rd param) value - EINVAL
29 1.1 christos
30 1.1 christos close(int fd);
31 1.1 christos 1) Attempt to close an invalid file descriptor - EBADF
32 1.1 christos
33 1.1 christos stat(const char *file_name, struct stat *buf);
34 1.1 christos 1) Pathname is a null string - ENOENT
35 1.1 christos 2) Pathname does not exist - ENOENT
36 1.1 christos
37 1.1 christos fstat(int filedes, struct stat *buf);
38 1.1 christos 1) Attempt to stat using an invalid file descriptor - EBADF
39 1.1 christos
40 1.1 christos isatty (int desc);
41 1.1 christos Not applicable. We will test that it returns 1 when expected and a case
42 1.1 christos where it should return 0.
43 1.1 christos
44 1.1 christos rename(const char *oldpath, const char *newpath);
45 1.1 christos 1) newpath is an existing directory, but oldpath is not a directory. - EISDIR
46 1.1 christos 2) newpath is a non-empty directory. - ENOTEMPTY or EEXIST
47 1.1 christos 3) newpath is a subdirectory of old path. - EINVAL
48 1.1 christos 4) oldpath does not exist. - ENOENT
49 1.1 christos
50 1.1 christos unlink(const char *pathname);
51 1.1 christos 1) pathname does not have write access. - EACCES
52 1.1 christos 2) pathname does not exist. - ENOENT
53 1.1 christos
54 1.1 christos time(time_t *t);
55 1.1 christos Not applicable.
56 1.1 christos
57 1.1 christos system (const char * string);
58 1.1 christos 1) Invalid string/command. - returns 127. */
59 1.1 christos static const char *strerrno (int err);
60 1.1 christos
61 1.1 christos /* Note that OUTDIR is defined by the test suite. */
62 1.1 christos #define FILENAME "foo.fileio.test"
63 1.1 christos #define RENAMED "bar.fileio.test"
64 1.1 christos #define NONEXISTANT "nofoo.fileio.test"
65 1.1 christos #define NOWRITE "nowrt.fileio.test"
66 1.1 christos #define TESTDIR1 "dir1.fileio.test"
67 1.1 christos #define TESTDIR2 "dir2.fileio.test"
68 1.1 christos #define TESTSUBDIR "dir1.fileio.test/subdir.fileio.test"
69 1.1 christos
70 1.1 christos #define STRING "Hello World"
71 1.1 christos
72 1.1 christos static void stop () {}
73 1.1 christos
74 1.1 christos int
75 1.1 christos test_open ()
76 1.1 christos {
77 1.1 christos int ret;
78 1.1 christos
79 1.1 christos /* Test opening */
80 1.1 christos errno = 0;
81 1.1 christos ret = open (OUTDIR FILENAME, O_CREAT | O_TRUNC | O_RDWR, S_IWUSR | S_IRUSR);
82 1.1 christos printf ("open 1: ret = %d, errno = %d %s\n", ret, errno,
83 1.1 christos ret >= 0 ? "OK" : "");
84 1.1 christos
85 1.1 christos if (ret >= 0)
86 1.1 christos close (ret);
87 1.1 christos stop ();
88 1.1 christos /* Creating an already existing file (created by fileio.exp) */
89 1.1 christos errno = 0;
90 1.1 christos ret = open (OUTDIR FILENAME, O_CREAT | O_EXCL | O_WRONLY, S_IWUSR | S_IRUSR);
91 1.1 christos printf ("open 2: ret = %d, errno = %d %s\n", ret, errno,
92 1.1 christos strerrno (errno));
93 1.1 christos if (ret >= 0)
94 1.1 christos close (ret);
95 1.1 christos stop ();
96 1.1 christos /* Open directory (for writing) */
97 1.1 christos errno = 0;
98 1.1 christos ret = open (".", O_WRONLY);
99 1.1 christos printf ("open 3: ret = %d, errno = %d %s\n", ret, errno,
100 1.1 christos strerrno (errno));
101 1.1 christos if (ret >= 0)
102 1.1 christos close (ret);
103 1.1 christos stop ();
104 1.1 christos /* Opening nonexistant file */
105 1.1 christos errno = 0;
106 1.1 christos ret = open (NONEXISTANT, O_RDONLY);
107 1.1 christos printf ("open 4: ret = %d, errno = %d %s\n", ret, errno,
108 1.1 christos strerrno (errno));
109 1.1 christos if (ret >= 0)
110 1.1 christos close (ret);
111 1.1 christos stop ();
112 1.1 christos /* Open for write but no write permission */
113 1.1 christos errno = 0;
114 1.1 christos ret = open (OUTDIR NOWRITE, O_CREAT | O_RDONLY, S_IRUSR);
115 1.1 christos if (ret >= 0)
116 1.1 christos {
117 1.1 christos close (ret);
118 1.1 christos stop ();
119 1.1 christos errno = 0;
120 1.1 christos ret = open (OUTDIR NOWRITE, O_WRONLY);
121 1.1 christos printf ("open 5: ret = %d, errno = %d %s\n", ret, errno,
122 1.1 christos strerrno (errno));
123 1.1 christos if (ret >= 0)
124 1.1 christos close (ret);
125 1.1 christos }
126 1.1 christos else
127 1.1 christos {
128 1.1 christos stop ();
129 1.1 christos printf ("open 5: ret = %d, errno = %d\n", ret, errno);
130 1.1 christos }
131 1.1 christos stop ();
132 1.1 christos }
133 1.1 christos
134 1.1 christos int
135 1.1 christos test_write ()
136 1.1 christos {
137 1.1 christos int fd, ret;
138 1.1 christos
139 1.1 christos /* Test writing */
140 1.1 christos errno = 0;
141 1.1 christos fd = open (OUTDIR FILENAME, O_WRONLY);
142 1.1 christos if (fd >= 0)
143 1.1 christos {
144 1.1 christos errno = 0;
145 1.1 christos ret = write (fd, STRING, strlen (STRING));
146 1.1 christos printf ("write 1: ret = %d, errno = %d %s\n", ret, errno,
147 1.1 christos ret == strlen (STRING) ? "OK" : "");
148 1.1 christos close (fd);
149 1.1 christos }
150 1.1 christos else
151 1.1 christos printf ("write 1: ret = %d, errno = %d\n", ret, errno);
152 1.1 christos stop ();
153 1.1 christos /* Write using invalid file descriptor */
154 1.1 christos errno = 0;
155 1.1 christos ret = write (999, STRING, strlen (STRING));
156 1.1 christos printf ("write 2: ret = %d, errno = %d, %s\n", ret, errno,
157 1.1 christos strerrno (errno));
158 1.1 christos stop ();
159 1.1 christos /* Write to a read-only file */
160 1.1 christos errno = 0;
161 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
162 1.1 christos if (fd >= 0)
163 1.1 christos {
164 1.1 christos errno = 0;
165 1.1 christos ret = write (fd, STRING, strlen (STRING));
166 1.1 christos printf ("write 3: ret = %d, errno = %d %s\n", ret, errno,
167 1.1 christos strerrno (errno));
168 1.1 christos }
169 1.1 christos else
170 1.1 christos printf ("write 3: ret = %d, errno = %d\n", ret, errno);
171 1.1 christos stop ();
172 1.1 christos }
173 1.1 christos
174 1.1 christos int
175 1.1 christos test_read ()
176 1.1 christos {
177 1.1 christos int fd, ret;
178 1.1 christos char buf[16];
179 1.1 christos
180 1.1 christos /* Test reading */
181 1.1 christos errno = 0;
182 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
183 1.1 christos if (fd >= 0)
184 1.1 christos {
185 1.1 christos memset (buf, 0, 16);
186 1.1 christos errno = 0;
187 1.1 christos ret = read (fd, buf, 16);
188 1.1 christos buf[15] = '\0'; /* Don't trust anybody... */
189 1.1 christos if (ret == strlen (STRING))
190 1.1 christos printf ("read 1: %s %s\n", buf, !strcmp (buf, STRING) ? "OK" : "");
191 1.1 christos else
192 1.1 christos printf ("read 1: ret = %d, errno = %d\n", ret, errno);
193 1.1 christos close (fd);
194 1.1 christos }
195 1.1 christos else
196 1.1 christos printf ("read 1: ret = %d, errno = %d\n", ret, errno);
197 1.1 christos stop ();
198 1.1 christos /* Read using invalid file descriptor */
199 1.1 christos errno = 0;
200 1.1 christos ret = read (999, buf, 16);
201 1.1 christos printf ("read 2: ret = %d, errno = %d %s\n", ret, errno,
202 1.1 christos strerrno (errno));
203 1.1 christos stop ();
204 1.1 christos }
205 1.1 christos
206 1.1 christos int
207 1.1 christos test_lseek ()
208 1.1 christos {
209 1.1 christos int fd;
210 1.1 christos off_t ret = 0;
211 1.1 christos
212 1.1 christos /* Test seeking */
213 1.1 christos errno = 0;
214 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
215 1.1 christos if (fd >= 0)
216 1.1 christos {
217 1.1 christos errno = 0;
218 1.1 christos ret = lseek (fd, 0, SEEK_CUR);
219 1.1 christos printf ("lseek 1: ret = %ld, errno = %d, %s\n", (long) ret, errno,
220 1.1 christos ret == 0 ? "OK" : "");
221 1.1 christos stop ();
222 1.1 christos errno = 0;
223 1.1 christos ret = lseek (fd, 0, SEEK_END);
224 1.1 christos printf ("lseek 2: ret = %ld, errno = %d, %s\n", (long) ret, errno,
225 1.1 christos ret == 11 ? "OK" : "");
226 1.1 christos stop ();
227 1.1 christos errno = 0;
228 1.1 christos ret = lseek (fd, 3, SEEK_SET);
229 1.1 christos printf ("lseek 3: ret = %ld, errno = %d, %s\n", (long) ret, errno,
230 1.1 christos ret == 3 ? "OK" : "");
231 1.1 christos close (fd);
232 1.1 christos }
233 1.1 christos else
234 1.1 christos {
235 1.1 christos printf ("lseek 1: ret = %ld, errno = %d %s\n", (long) ret, errno,
236 1.1 christos strerrno (errno));
237 1.1 christos stop ();
238 1.1 christos printf ("lseek 2: ret = %ld, errno = %d %s\n", (long) ret, errno,
239 1.1 christos strerrno (errno));
240 1.1 christos stop ();
241 1.1 christos printf ("lseek 3: ret = %ld, errno = %d %s\n", (long) ret, errno,
242 1.1 christos strerrno (errno));
243 1.1 christos }
244 1.1 christos /* Seeking on an invalid file descriptor */
245 1.1 christos stop ();
246 1.1 christos }
247 1.1 christos
248 1.1 christos int
249 1.1 christos test_close ()
250 1.1 christos {
251 1.1 christos int fd, ret;
252 1.1 christos
253 1.1 christos /* Test close */
254 1.1 christos errno = 0;
255 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
256 1.1 christos if (fd >= 0)
257 1.1 christos {
258 1.1 christos errno = 0;
259 1.1 christos ret = close (fd);
260 1.1 christos printf ("close 1: ret = %d, errno = %d, %s\n", ret, errno,
261 1.1 christos ret == 0 ? "OK" : "");
262 1.1 christos }
263 1.1 christos else
264 1.1 christos printf ("close 1: ret = %d, errno = %d\n", ret, errno);
265 1.1 christos stop ();
266 1.1 christos /* Close an invalid file descriptor */
267 1.1 christos errno = 0;
268 1.1 christos ret = close (999);
269 1.1 christos printf ("close 2: ret = %d, errno = %d, %s\n", ret, errno,
270 1.1 christos strerrno (errno));
271 1.1 christos stop ();
272 1.1 christos }
273 1.1 christos
274 1.1 christos int
275 1.1 christos test_stat ()
276 1.1 christos {
277 1.1 christos int ret;
278 1.1 christos struct stat st;
279 1.1 christos
280 1.1 christos /* Test stat */
281 1.1 christos errno = 0;
282 1.1 christos ret = stat (OUTDIR FILENAME, &st);
283 1.1 christos if (!ret)
284 1.1 christos printf ("stat 1: ret = %d, errno = %d %s\n", ret, errno,
285 1.1 christos st.st_size == 11 ? "OK" : "");
286 1.1 christos else
287 1.1 christos printf ("stat 1: ret = %d, errno = %d\n", ret, errno);
288 1.1 christos stop ();
289 1.1 christos /* NULL pathname */
290 1.1 christos errno = 0;
291 1.1 christos ret = stat (NULL, &st);
292 1.1 christos printf ("stat 2: ret = %d, errno = %d %s\n", ret, errno,
293 1.1 christos strerrno (errno));
294 1.1 christos stop ();
295 1.1 christos /* Empty pathname */
296 1.1 christos errno = 0;
297 1.1 christos ret = stat ("", &st);
298 1.1 christos printf ("stat 3: ret = %d, errno = %d %s\n", ret, errno,
299 1.1 christos strerrno (errno));
300 1.1 christos stop ();
301 1.1 christos /* Nonexistant file */
302 1.1 christos errno = 0;
303 1.1 christos ret = stat (NONEXISTANT, &st);
304 1.1 christos printf ("stat 4: ret = %d, errno = %d %s\n", ret, errno,
305 1.1 christos strerrno (errno));
306 1.1 christos stop ();
307 1.1 christos }
308 1.1 christos
309 1.1 christos int
310 1.1 christos test_fstat ()
311 1.1 christos {
312 1.1 christos int fd, ret;
313 1.1 christos struct stat st;
314 1.1 christos
315 1.1 christos /* Test fstat */
316 1.1 christos errno = 0;
317 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
318 1.1 christos if (fd >= 0)
319 1.1 christos {
320 1.1 christos errno = 0;
321 1.1 christos ret = fstat (fd, &st);
322 1.1 christos if (!ret)
323 1.1 christos printf ("fstat 1: ret = %d, errno = %d %s\n", ret, errno,
324 1.1 christos st.st_size == 11 ? "OK" : "");
325 1.1 christos else
326 1.1 christos printf ("fstat 1: ret = %d, errno = %d\n", ret, errno);
327 1.1 christos close (fd);
328 1.1 christos }
329 1.1 christos else
330 1.1 christos printf ("fstat 1: ret = %d, errno = %d\n", ret, errno);
331 1.1 christos stop ();
332 1.1 christos /* Fstat using invalid file descriptor */
333 1.1 christos errno = 0;
334 1.1 christos ret = fstat (999, &st);
335 1.1 christos printf ("fstat 2: ret = %d, errno = %d %s\n", ret, errno,
336 1.1 christos strerrno (errno));
337 1.1 christos stop ();
338 1.1 christos }
339 1.1 christos
340 1.1 christos int
341 1.1 christos test_isatty ()
342 1.1 christos {
343 1.1 christos int fd;
344 1.1 christos
345 1.1 christos /* Check std I/O */
346 1.1 christos printf ("isatty 1: stdin %s\n", isatty (0) ? "yes OK" : "no");
347 1.1 christos stop ();
348 1.1 christos printf ("isatty 2: stdout %s\n", isatty (1) ? "yes OK" : "no");
349 1.1 christos stop ();
350 1.1 christos printf ("isatty 3: stderr %s\n", isatty (2) ? "yes OK" : "no");
351 1.1 christos stop ();
352 1.1 christos /* Check invalid fd */
353 1.1 christos printf ("isatty 4: invalid %s\n", isatty (999) ? "yes" : "no OK");
354 1.1 christos stop ();
355 1.1 christos /* Check open file */
356 1.1 christos fd = open (OUTDIR FILENAME, O_RDONLY);
357 1.1 christos if (fd >= 0)
358 1.1 christos {
359 1.1 christos printf ("isatty 5: file %s\n", isatty (fd) ? "yes" : "no OK");
360 1.1 christos close (fd);
361 1.1 christos }
362 1.1 christos else
363 1.1 christos printf ("isatty 5: file couldn't open\n");
364 1.1 christos stop ();
365 1.1 christos }
366 1.1 christos
367 1.1 christos
368 1.1 christos char sys[1512];
369 1.1 christos
370 1.1 christos int
371 1.1 christos test_system ()
372 1.1 christos {
373 1.1 christos /*
374 1.1 christos * Requires test framework to switch on "set remote system-call-allowed 1"
375 1.1 christos */
376 1.1 christos int ret;
377 1.1 christos
378 1.1 christos /* Test for shell */
379 1.1 christos ret = system (NULL);
380 1.1 christos printf ("system 1: ret = %d %s\n", ret, ret != 0 ? "OK" : "");
381 1.1 christos stop ();
382 1.1 christos /* This test prepares the directory for test_rename() */
383 1.1 christos sprintf (sys, "mkdir -p %s/%s %s/%s", OUTDIR, TESTSUBDIR, OUTDIR, TESTDIR2);
384 1.1 christos ret = system (sys);
385 1.1 christos if (ret == 127)
386 1.1 christos printf ("system 2: ret = %d /bin/sh unavailable???\n", ret);
387 1.1 christos else
388 1.1 christos printf ("system 2: ret = %d %s\n", ret, ret == 0 ? "OK" : "");
389 1.1 christos stop ();
390 1.1 christos /* Invalid command (just guessing ;-) ) */
391 1.1 christos ret = system ("wrtzlpfrmpft");
392 1.1 christos printf ("system 3: ret = %d %s\n", ret, WEXITSTATUS (ret) == 127 ? "OK" : "");
393 1.1 christos stop ();
394 1.1 christos }
395 1.1 christos
396 1.1 christos int
397 1.1 christos test_rename ()
398 1.1 christos {
399 1.1 christos int ret;
400 1.1 christos struct stat st;
401 1.1 christos
402 1.1 christos /* Test rename */
403 1.1 christos errno = 0;
404 1.1 christos ret = rename (OUTDIR FILENAME, OUTDIR RENAMED);
405 1.1 christos if (!ret)
406 1.1 christos {
407 1.1 christos errno = 0;
408 1.1 christos ret = stat (FILENAME, &st);
409 1.1 christos if (ret && errno == ENOENT)
410 1.1 christos {
411 1.1 christos errno = 0;
412 1.1 christos ret = stat (OUTDIR RENAMED, &st);
413 1.1 christos printf ("rename 1: ret = %d, errno = %d %s\n", ret, errno,
414 1.1 christos strerrno (errno));
415 1.1 christos errno = 0;
416 1.1 christos }
417 1.1 christos else
418 1.1 christos printf ("rename 1: ret = %d, errno = %d\n", ret, errno);
419 1.1 christos }
420 1.1 christos else
421 1.1 christos printf ("rename 1: ret = %d, errno = %d\n", ret, errno);
422 1.1 christos stop ();
423 1.1 christos /* newpath is existing directory, oldpath is not a directory */
424 1.1 christos errno = 0;
425 1.1 christos ret = rename (OUTDIR RENAMED, OUTDIR TESTDIR2);
426 1.1 christos printf ("rename 2: ret = %d, errno = %d %s\n", ret, errno,
427 1.1 christos strerrno (errno));
428 1.1 christos stop ();
429 1.1 christos /* newpath is a non-empty directory */
430 1.1 christos errno = 0;
431 1.1 christos ret = rename (OUTDIR TESTDIR2, OUTDIR TESTDIR1);
432 1.1 christos printf ("rename 3: ret = %d, errno = %d %s\n", ret, errno,
433 1.1 christos strerrno (errno));
434 1.1 christos stop ();
435 1.1 christos /* newpath is a subdirectory of old path */
436 1.1 christos errno = 0;
437 1.1 christos ret = rename (OUTDIR TESTDIR1, OUTDIR TESTSUBDIR);
438 1.1 christos printf ("rename 4: ret = %d, errno = %d %s\n", ret, errno,
439 1.1 christos strerrno (errno));
440 1.1 christos stop ();
441 1.1 christos /* oldpath does not exist */
442 1.1 christos errno = 0;
443 1.1 christos ret = rename (OUTDIR NONEXISTANT, OUTDIR FILENAME);
444 1.1 christos printf ("rename 5: ret = %d, errno = %d %s\n", ret, errno,
445 1.1 christos strerrno (errno));
446 1.1 christos stop ();
447 1.1 christos }
448 1.1 christos
449 1.1 christos char name[1256];
450 1.1 christos
451 1.1 christos int
452 1.1 christos test_unlink ()
453 1.1 christos {
454 1.1 christos int ret;
455 1.1 christos
456 1.1 christos /* Test unlink */
457 1.1 christos errno = 0;
458 1.1 christos ret = unlink (OUTDIR RENAMED);
459 1.1 christos printf ("unlink 1: ret = %d, errno = %d %s\n", ret, errno,
460 1.1 christos strerrno (errno));
461 1.1 christos stop ();
462 1.1 christos /* No write access */
463 1.1 christos sprintf (name, "%s/%s/%s", OUTDIR, TESTDIR2, FILENAME);
464 1.1 christos errno = 0;
465 1.1 christos ret = open (name, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
466 1.1 christos if (ret >= 0)
467 1.1 christos {
468 1.1 christos sprintf (sys, "chmod -w %s/%s", OUTDIR, TESTDIR2);
469 1.1 christos ret = system (sys);
470 1.1 christos if (!ret)
471 1.1 christos {
472 1.1 christos errno = 0;
473 1.1 christos ret = unlink (name);
474 1.1 christos printf ("unlink 2: ret = %d, errno = %d %s\n", ret, errno,
475 1.1 christos strerrno (errno));
476 1.1 christos }
477 1.1 christos else
478 1.1 christos printf ("unlink 2: ret = %d chmod failed, errno= %d\n", ret, errno);
479 1.1 christos }
480 1.1 christos else
481 1.1 christos printf ("unlink 2: ret = %d, errno = %d\n", ret, errno);
482 1.1 christos stop ();
483 1.1 christos /* pathname doesn't exist */
484 1.1 christos errno = 0;
485 1.1 christos ret = unlink (OUTDIR NONEXISTANT);
486 1.1 christos printf ("unlink 3: ret = %d, errno = %d %s\n", ret, errno,
487 1.1 christos strerrno (errno));
488 1.1 christos stop ();
489 1.1 christos }
490 1.1 christos
491 1.1 christos int
492 1.1 christos test_time ()
493 1.1 christos {
494 1.1 christos time_t ret, t;
495 1.1 christos
496 1.1 christos errno = 0;
497 1.1 christos ret = time (&t);
498 1.1 christos printf ("time 1: ret = %ld, errno = %d, t = %ld %s\n", (long) ret, errno, (long) t, ret == t ? "OK" : "");
499 1.1 christos stop ();
500 1.1 christos errno = 0;
501 1.1 christos ret = time (NULL);
502 1.1 christos printf ("time 2: ret = %ld, errno = %d, t = %ld %s\n",
503 1.1 christos (long) ret, errno, (long) t, ret >= t && ret < t + 10 ? "OK" : "");
504 1.1 christos stop ();
505 1.1 christos }
506 1.1 christos
507 1.1 christos static const char *
508 1.1 christos strerrno (int err)
509 1.1 christos {
510 1.1 christos switch (err)
511 1.1 christos {
512 1.1 christos case 0: return "OK";
513 1.1 christos #ifdef EACCES
514 1.1 christos case EACCES: return "EACCES";
515 1.1 christos #endif
516 1.1 christos #ifdef EBADF
517 1.1 christos case EBADF: return "EBADF";
518 1.1 christos #endif
519 1.1 christos #ifdef EEXIST
520 1.1 christos case EEXIST: return "EEXIST";
521 1.1 christos #endif
522 1.1 christos #ifdef EFAULT
523 1.1 christos case EFAULT: return "EFAULT";
524 1.1 christos #endif
525 1.1 christos #ifdef EINVAL
526 1.1 christos case EINVAL: return "EINVAL";
527 1.1 christos #endif
528 1.1 christos #ifdef EISDIR
529 1.1 christos case EISDIR: return "EISDIR";
530 1.1 christos #endif
531 1.1 christos #ifdef ENOENT
532 1.1 christos case ENOENT: return "ENOENT";
533 1.1 christos #endif
534 1.1 christos #ifdef ENOTEMPTY
535 1.1 christos case ENOTEMPTY: return "ENOTEMPTY";
536 1.1 christos #endif
537 1.1 christos #ifdef EBUSY
538 1.1 christos case EBUSY: return "EBUSY";
539 1.1 christos #endif
540 1.1 christos default: return "E??";
541 1.1 christos }
542 1.1 christos }
543 1.1 christos
544 1.1 christos int
545 1.1 christos main ()
546 1.1 christos {
547 1.1 christos /* Don't change the order of the calls. They partly depend on each other */
548 1.1 christos test_open ();
549 1.1 christos test_write ();
550 1.1 christos test_read ();
551 1.1 christos test_lseek ();
552 1.1 christos test_close ();
553 1.1 christos test_stat ();
554 1.1 christos test_fstat ();
555 1.1 christos test_isatty ();
556 1.1 christos test_system ();
557 1.1 christos test_rename ();
558 1.1 christos test_unlink ();
559 1.1 christos test_time ();
560 1.1 christos return 0;
561 1.1 christos }
562