[klibc] Add remove()
remove() is unlink() for a file or rmdir() for a directory.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/include/stdio.h b/include/stdio.h
index b009def..8850b4c 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -124,4 +124,6 @@
__extern int rename(const char *, const char *);
__extern int renameat(int, const char *, int, const char *);
+__extern int remove(const char *);
+
#endif /* _STDIO_H */
diff --git a/klibc/Kbuild b/klibc/Kbuild
index c324909..0e67d95 100644
--- a/klibc/Kbuild
+++ b/klibc/Kbuild
@@ -38,7 +38,7 @@
seteuid.o setegid.o \
getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
clearenv.o nullenv.o \
- getopt.o readdir.o \
+ getopt.o readdir.o remove.o \
syslog.o closelog.o pty.o getpt.o isatty.o reboot.o \
time.o utime.o llseek.o nice.o getpriority.o \
qsort.o \
diff --git a/klibc/remove.c b/klibc/remove.c
new file mode 100644
index 0000000..355882d
--- /dev/null
+++ b/klibc/remove.c
@@ -0,0 +1,18 @@
+/*
+ * remove.c
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+int remove(const char *pathname)
+{
+ int rv;
+
+ rv = unlink(pathname);
+ if (rv == -1 && errno == EISDIR)
+ return rmdir(pathname);
+
+ return rv;
+}