forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest14.c
More file actions
79 lines (64 loc) · 1.36 KB
/
Copy pathtest14.c
File metadata and controls
79 lines (64 loc) · 1.36 KB
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
/* Test 14. unlinking an open file. */
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define TRIALS 100
#define MAX_ERROR 4
char name[20] = {"TMP14."};
int errct;
int subtest = 1;
_PROTOTYPE(int main, (void));
_PROTOTYPE(void e, (int n));
_PROTOTYPE(void quit, (void));
int main()
{
int fd0, i, pid;
printf("Test 14 ");
fflush(stdout);
system("rm -rf DIR_14; mkdir DIR_14");
chdir("DIR_14");
pid = getpid();
name[6] = (pid & 037) + 33;
name[7] = ((pid * pid) & 037) + 33;
name[8] = 0;
for (i = 0; i < TRIALS; i++) {
if ( (fd0 = creat(name, 0777)) < 0) e(1);
if (write(fd0, name, 20) != 20) e(2);
if (unlink(name) != 0) e(3);
if (close(fd0) != 0) e(4);
}
fd0 = creat(name, 0777);
write(fd0, name, 20);
unlink(name);
quit();
return(-1); /* impossible */
}
void e(n)
int n;
{
int err_num = errno; /* save errno in case printf clobbers it */
printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
errno = err_num; /* restore errno, just in case */
perror("");
if (errct++ > MAX_ERROR) {
printf("Too many errors; test aborted\n");
chdir("..");
system("rm -rf DIR*");
exit(1);
}
}
void quit()
{
chdir("..");
system("rm -rf DIR*");
if (errct == 0) {
printf("ok\n");
exit(0);
} else {
printf("%d errors\n", errct);
exit(1);
}
}