diff options
author | dzwdz | 2024-07-20 23:17:36 +0200 |
---|---|---|
committer | dzwdz | 2024-07-20 23:17:36 +0200 |
commit | 1fc2d9c88af77c3af81b6bd461e6b019b97d2dbb (patch) | |
tree | 56d19935958983882872495f556bdb74c8ae26b8 /src/libc/stdio/misc.c | |
parent | e88aee660ea668cc96d8a5a11060b6e02b2f0fd7 (diff) |
*: moving files
Diffstat (limited to 'src/libc/stdio/misc.c')
-rw-r--r-- | src/libc/stdio/misc.c | 30 |
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 |