1*433d6423SLionel Sambuc /* Test 14. unlinking an open file. */
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc #include <sys/types.h>
4*433d6423SLionel Sambuc #include <errno.h>
5*433d6423SLionel Sambuc #include <fcntl.h>
6*433d6423SLionel Sambuc #include <stdlib.h>
7*433d6423SLionel Sambuc #include <unistd.h>
8*433d6423SLionel Sambuc #include <stdio.h>
9*433d6423SLionel Sambuc
10*433d6423SLionel Sambuc #define TRIALS 100
11*433d6423SLionel Sambuc int max_error = 4;
12*433d6423SLionel Sambuc #include "common.h"
13*433d6423SLionel Sambuc
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc char name[20] = {"TMP14."};
16*433d6423SLionel Sambuc int subtest = 1;
17*433d6423SLionel Sambuc
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc int main(void);
20*433d6423SLionel Sambuc void quit(void);
21*433d6423SLionel Sambuc
main()22*433d6423SLionel Sambuc int main()
23*433d6423SLionel Sambuc {
24*433d6423SLionel Sambuc int fd0, i, pid;
25*433d6423SLionel Sambuc
26*433d6423SLionel Sambuc start(14);
27*433d6423SLionel Sambuc
28*433d6423SLionel Sambuc pid = getpid();
29*433d6423SLionel Sambuc sprintf(&name[6], "%x", pid);
30*433d6423SLionel Sambuc
31*433d6423SLionel Sambuc for (i = 0; i < TRIALS; i++) {
32*433d6423SLionel Sambuc if ( (fd0 = creat(name, 0777)) < 0) e(1);
33*433d6423SLionel Sambuc if (write(fd0, name, 20) != 20) e(2);
34*433d6423SLionel Sambuc if (unlink(name) != 0) e(3);
35*433d6423SLionel Sambuc if (close(fd0) != 0) e(4);
36*433d6423SLionel Sambuc }
37*433d6423SLionel Sambuc
38*433d6423SLionel Sambuc fd0 = creat(name, 0777);
39*433d6423SLionel Sambuc write(fd0, name, 20);
40*433d6423SLionel Sambuc unlink(name);
41*433d6423SLionel Sambuc quit();
42*433d6423SLionel Sambuc return(-1); /* impossible */
43*433d6423SLionel Sambuc }
44*433d6423SLionel Sambuc
45