summaryrefslogtreecommitdiff
path: root/src/stdio/remove.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/remove.c')
-rw-r--r--src/stdio/remove.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/stdio/remove.c b/src/stdio/remove.c
new file mode 100644
index 00000000..2a10e443
--- /dev/null
+++ b/src/stdio/remove.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+
+#ifdef _POSIX_SOURCE
+#include "sys/types.h"
+#include "sys/stat.h"
+#include "unistd.h"
+#else
+ struct stat { int st_mode; };
+#define stat(f, b) (void)f
+#define S_ISDIR(m) (m = 0)
+#define rmdir(f) (-1)
+#define unlink(f) (-1)
+#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)
+*/