blob: 39b5a74cfd9dc3fc1e4b78912638d23c3b635a08 (
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
|
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#define POSIX_FORCED
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef POSIX_FORCED
#include "_syscall.h"
#define stat(_f, _b) __scall2(stat, _f, _b)
#define rmdir(_f) __scall1(rmdir, _f)
#define unlink(_f) __scall1(unlink, _f)
#endif
/** delete a file **/
int remove(const char *filename)
{
struct stat st;
stat(filename, &st);
if (S_ISDIR(st.st_mode)) {
return rmdir(filename);
}
return unlink(filename);
}
/***
function removes the file ARGUMENT(filename) so the future attempts to
open that file will fail unless creating a new file.
***/
/*
IMPLEMENTATION(Whether the file is removed if it is open)
STDC(1)
*/
|