2005-04-21 16:53:53 +02:00
|
|
|
/* 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 subtest = 1;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
#include "common.c"
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
_PROTOTYPE(int main, (void));
|
|
|
|
_PROTOTYPE(void e, (int n));
|
|
|
|
_PROTOTYPE(void quit, (void));
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int fd0, i, pid;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
start(14);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
pid = getpid();
|
2009-08-15 17:13:57 +02:00
|
|
|
sprintf(&name[6], "%x", pid);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|