summaryrefslogtreecommitdiff
path: root/src/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'src/libc/stdio')
-rw-r--r--src/libc/stdio/misc.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/libc/stdio/misc.c b/src/libc/stdio/misc.c
index 7e8e746..6cd5b35 100644
--- a/src/libc/stdio/misc.c
+++ b/src/libc/stdio/misc.c
@@ -1,3 +1,6 @@
+#include <camellia.h>
+#include <camellia/flags.h>
+#include <camellia/syscalls.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -30,11 +33,28 @@ int remove(const char *path) {
return unlink(path);
}
-// TODO! VFSOP_MOVE
-int rename(const char *old, const char *new) {
- (void)old; (void)new;
- errno = ENOSYS;
- return -1;
+int rename(const char *oldpath, const char *newpath) {
+ // TODO require a duplex flag in open()
+ hid_t from, to;
+ from = camellia_open(oldpath, OPEN_RW);
+ if (from < 0) {
+ return -1;
+ }
+ to = camellia_open(newpath, OPEN_WRITE | OPEN_CREATE);
+ if (to < 0) {
+ close(from);
+ return -1;
+ }
+
+ long ret = _sys_duplex(from, to, DUPLEX_REMOVE);
+ close(from);
+ close(to);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ } else {
+ return 0;
+ }
}
// TODO tmpnam