summaryrefslogtreecommitdiff
path: root/minix/tests/test14.c
blob: fc85cd5cd318f416895f1700ab4bf5ace47002d4 (plain)
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
/* 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
int max_error = 4;
#include "common.h"


char name[20] = {"TMP14."};
int subtest = 1;


int main(void);
void quit(void);

int main()
{
  int fd0, i, pid;

  start(14);

  pid = getpid();
  sprintf(&name[6], "%x", pid);

  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 */
}