From 4be2181f89d7bf02827ba7bd0f2d85e2098c843e Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Sun, 3 Sep 2017 23:46:18 +0200 Subject: [PATCH] libposix: add readlink and readlinkat (both failing with EINVAL) --- sys/src/lib/posix/build.json | 1 + sys/src/lib/posix/files.c | 38 ------------------ sys/src/lib/posix/links.c | 74 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 sys/src/lib/posix/links.c diff --git a/sys/src/lib/posix/build.json b/sys/src/lib/posix/build.json index fe2da9d..ff4998e 100644 --- a/sys/src/lib/posix/build.json +++ b/sys/src/lib/posix/build.json @@ -14,6 +14,7 @@ "errors.c", "files.c", "initlib.c", + "links.c", "memory.c", "others.c", "processes.c", diff --git a/sys/src/lib/posix/files.c b/sys/src/lib/posix/files.c index 161ef70..e01f9db 100644 --- a/sys/src/lib/posix/files.c +++ b/sys/src/lib/posix/files.c @@ -357,31 +357,6 @@ POSIX_close(int *errno, int file) return -1; } -int -POSIX_link(int *errnop, const char *old, const char *new) -{ - int err; - /* let choose the most appropriate error */ - if(old == nil || new == nil || old[0] == 0 || new[0] == 0) - err = __libposix_get_errno(PosixENOENT); - else if(access(new, AEXIST) == 0) - err = __libposix_get_errno(PosixEEXIST); - else if(access(old, AEXIST) == 0) - err = __libposix_get_errno(PosixENOENT); - else { - /* Jehanne does not support links. - * A custom overlay filesystem might support them in - * the future but so far it does not exists yet. - * - * We return EXDEV so that a posix compliant caller - * can fallback to a simple copy. - */ - err = __libposix_get_errno(PosixEXDEV); - } - *errnop = err; - return -1; -} - int POSIX_unlink(int *errnop, const char *name) { @@ -459,12 +434,6 @@ POSIX_stat(int *errnop, const char *file, void *pstat) return -1; } -int -POSIX_lstat(int *errnop, const char *file, void *pstat) -{ - return POSIX_stat(errnop, file, pstat); -} - int POSIX_chmod(int *errnop, const char *path, int mode) { @@ -581,13 +550,6 @@ POSIX_fchownat(int *errnop, int fd, const char *path, int owner, int group, int return 0; } -int -POSIX_lchown(int *errnop, const char *path, int owner, int group) -{ - /* TODO: implement when actually needed */ - return 0; -} - int POSIX_chdir(int *errnop, const char *path) { diff --git a/sys/src/lib/posix/links.c b/sys/src/lib/posix/links.c new file mode 100644 index 0000000..ad37819 --- /dev/null +++ b/sys/src/lib/posix/links.c @@ -0,0 +1,74 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3 of the License. + * + * Jehanne 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 General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Jehanne. If not, see . + */ +#include +#include +#include <9P2000.h> +#include +#include "internal.h" + +int +POSIX_lchown(int *errnop, const char *path, int owner, int group) +{ + /* TODO: implement when actually needed */ + return 0; +} + +int +POSIX_link(int *errnop, const char *old, const char *new) +{ + int err; + /* let choose the most appropriate error */ + if(old == nil || new == nil || old[0] == 0 || new[0] == 0) + err = __libposix_get_errno(PosixENOENT); + else if(access(new, AEXIST) == 0) + err = __libposix_get_errno(PosixEEXIST); + else if(access(old, AEXIST) == 0) + err = __libposix_get_errno(PosixENOENT); + else { + /* Jehanne does not support links. + * A custom overlay filesystem might support them in + * the future but so far it does not exists yet. + * + * We return EXDEV so that a posix compliant caller + * can fallback to a simple copy. + */ + err = __libposix_get_errno(PosixEXDEV); + } + *errnop = err; + return -1; +} + +int +POSIX_lstat(int *errnop, const char *file, void *pstat) +{ + return POSIX_stat(errnop, file, pstat); +} + +int +POSIX_readlink(int *errnop, const char *path, char *buf, int bufsize) +{ + *errnop = __libposix_get_errno(PosixEINVAL); + return -1; +} + +int +POSIX_readlinkat(int *errnop, int fd, const char *path, char *buf, int bufsize) +{ + *errnop = __libposix_get_errno(PosixEINVAL); + return -1; +}