diff --git a/libc/Makefile b/libc/Makefile
index 3f029bc5..68a88226 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -187,6 +187,8 @@ raise.o \
rand.o \
readdirents.o \
read.o \
+removeat.o \
+remove.o \
rmdir.o \
sbrk.o \
scanf.o \
diff --git a/libc/fdio.c b/libc/fdio.c
index 20a3bbd3..e1385d26 100644
--- a/libc/fdio.c
+++ b/libc/fdio.c
@@ -207,14 +207,3 @@ FILE* fopen(const char* path, const char* mode)
if ( !fp ) { close(fd); return NULL; }
return fp;
}
-
-int remove(const char* pathname)
-{
- int result = unlink(pathname);
- if ( result && errno == EISDIR )
- {
- // TODO: rmdir is unimplemented.
- // result = rmdir(pathname);
- }
- return result;
-}
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index eabf58e9..ff8a09ab 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -102,6 +102,7 @@ extern int printf(const char* restrict format, ...);
extern int putc(int c, FILE* stream);
extern int putchar(int c);
extern int puts(const char* str);
+extern int removeat(int dirrfd, const char* path);
extern int remove(const char* path);
extern int rename(const char* oldname, const char* newname);
extern void rewind(FILE* stream);
diff --git a/libc/remove.cpp b/libc/remove.cpp
new file mode 100644
index 00000000..44877f78
--- /dev/null
+++ b/libc/remove.cpp
@@ -0,0 +1,31 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ remove.cpp
+ Remove a file or directory.
+
+*******************************************************************************/
+
+#include
+#include
+
+extern "C" int remove(const char* path)
+{
+ return removeat(AT_FDCWD, path);
+}
diff --git a/libc/removeat.cpp b/libc/removeat.cpp
new file mode 100644
index 00000000..60cf87d3
--- /dev/null
+++ b/libc/removeat.cpp
@@ -0,0 +1,32 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ removeat.cpp
+ Remove a file or directory.
+
+*******************************************************************************/
+
+#include
+#include
+#include
+
+extern "C" int removeat(int dirfd, const char* path)
+{
+ return unlinkat(dirfd, path, AT_REMOVEDIR | AT_REMOVEFILE);
+}