From 4de95c9bc0ae81eb92d239b712daa629efa612cb Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Wed, 23 Aug 2017 02:57:41 +0200 Subject: [PATCH] libposix: make AT_FDCWD value configurable --- sys/include/posix.h | 4 ++++ sys/src/lib/posix/files.c | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sys/include/posix.h b/sys/include/posix.h index 35bbb45..a055750 100644 --- a/sys/include/posix.h +++ b/sys/include/posix.h @@ -180,6 +180,7 @@ typedef enum PosixSignals * * libposix_define_errno to set the value of each PosixError * libposix_define_signal to set the value of each PosixSignal + * libposix_define_at_fdcwd to set the value of AT_FDCWD (for fchmodat) * libposix_translate_error to translate error strings to PosixError * libposix_set_signal_trampoline to dispatch signal received as notes * libposix_set_stat_reader @@ -206,6 +207,9 @@ typedef PosixError (*PosixErrorTranslator)(char* error, uintptr_t caller); */ extern int libposix_translate_error(PosixErrorTranslator translation, uintptr_t caller); +/* define the value of AT_FDCWD according to the library headers */ +extern int libposix_define_at_fdcwd(int AT_FDCWD); + /* define the value of a specific PosixError according to the library headers */ extern int libposix_define_errno(PosixError e, int errno); diff --git a/sys/src/lib/posix/files.c b/sys/src/lib/posix/files.c index bdc6998..3999262 100644 --- a/sys/src/lib/posix/files.c +++ b/sys/src/lib/posix/files.c @@ -23,6 +23,7 @@ static PosixStatReader __libposix_stat_reader; static PosixOpenTranslator __libposix_open_translation; +static int __libposix_AT_FDCWD; typedef enum SeekTypes { @@ -409,14 +410,13 @@ FailWithError: int POSIX_fchmodat(int *errnop, int fd, const char *path, long mode, int flag) { -#define AT_FDCWD -100 /* from NetBSD; TODO: get from configuration */ Dir *dir, ndir; long cperm = 0; char fullpath[4096], *p; int l; PosixError e; - if(fd == AT_FDCWD){ + if(fd == __libposix_AT_FDCWD){ return POSIX_chmod(errnop, path, mode); } else if(path == nil){ e = PosixENOENT; @@ -560,3 +560,12 @@ FailWithEIO: *errnop = __libposix_get_errno(PosixEIO); return -1; } + +int +libposix_define_at_fdcwd(int AT_FDCWD) +{ + if(__libposix_AT_FDCWD != 0) + return -1; + __libposix_AT_FDCWD = AT_FDCWD; + return 0; +}