source: trunk/minix/test/test14.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1/* Test 14. unlinking an open file. */
2
3#include <sys/types.h>
4#include <errno.h>
5#include <fcntl.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <stdio.h>
9
10#define TRIALS 100
11#define MAX_ERROR 4
12
13char name[20] = {"TMP14."};
14int errct;
15int subtest = 1;
16
17_PROTOTYPE(int main, (void));
18_PROTOTYPE(void e, (int n));
19_PROTOTYPE(void quit, (void));
20
21int main()
22{
23 int fd0, i, pid;
24
25 printf("Test 14 ");
26 fflush(stdout);
27
28 system("rm -rf DIR_14; mkdir DIR_14");
29 chdir("DIR_14");
30
31 pid = getpid();
32 name[6] = (pid & 037) + 33;
33 name[7] = ((pid * pid) & 037) + 33;
34 name[8] = 0;
35
36 for (i = 0; i < TRIALS; i++) {
37 if ( (fd0 = creat(name, 0777)) < 0) e(1);
38 if (write(fd0, name, 20) != 20) e(2);
39 if (unlink(name) != 0) e(3);
40 if (close(fd0) != 0) e(4);
41 }
42
43 fd0 = creat(name, 0777);
44 write(fd0, name, 20);
45 unlink(name);
46 quit();
47 return(-1); /* impossible */
48}
49
50void e(n)
51int n;
52{
53 int err_num = errno; /* save errno in case printf clobbers it */
54
55 printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
56 errno = err_num; /* restore errno, just in case */
57 perror("");
58 if (errct++ > MAX_ERROR) {
59 printf("Too many errors; test aborted\n");
60 chdir("..");
61 system("rm -rf DIR*");
62 exit(1);
63 }
64}
65
66void quit()
67{
68
69 chdir("..");
70 system("rm -rf DIR*");
71
72 if (errct == 0) {
73 printf("ok\n");
74 exit(0);
75 } else {
76 printf("%d errors\n", errct);
77 exit(1);
78 }
79}
Note: See TracBrowser for help on using the repository browser.