From 1fc2d9c88af77c3af81b6bd461e6b019b97d2dbb Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 20 Jul 2024 23:17:36 +0200 Subject: *: moving files --- src/libc/stdio/misc.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/libc/stdio/misc.c') 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 +#include +#include #include #include #include @@ -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 -- cgit v1.2.3