Uninitialized vector entry?
[minix3.git] / test / test14.c
blobc96c1e24b1d3d1820ab8a3001d09b1289d920bc4
1 /* Test 14. unlinking an open file. */
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>
10 #define TRIALS 100
11 #define MAX_ERROR 4
13 char name[20] = {"TMP14."};
14 int errct;
15 int subtest = 1;
17 _PROTOTYPE(int main, (void));
18 _PROTOTYPE(void e, (int n));
19 _PROTOTYPE(void quit, (void));
21 int main()
23 int fd0, i, pid;
25 printf("Test 14 ");
26 fflush(stdout);
28 system("rm -rf DIR_14; mkdir DIR_14");
29 chdir("DIR_14");
31 pid = getpid();
32 name[6] = (pid & 037) + 33;
33 name[7] = ((pid * pid) & 037) + 33;
34 name[8] = 0;
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);
43 fd0 = creat(name, 0777);
44 write(fd0, name, 20);
45 unlink(name);
46 quit();
47 return(-1); /* impossible */
50 void e(n)
51 int n;
53 int err_num = errno; /* save errno in case printf clobbers it */
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);
66 void quit()
69 chdir("..");
70 system("rm -rf DIR*");
72 if (errct == 0) {
73 printf("ok\n");
74 exit(0);
75 } else {
76 printf("%d errors\n", errct);
77 exit(1);