libposix: make AT_FDCWD value configurable

This commit is contained in:
Giacomo Tesio 2017-08-23 02:57:41 +02:00
parent 61c4849bd7
commit 4de95c9bc0
2 changed files with 15 additions and 2 deletions

View File

@ -180,6 +180,7 @@ typedef enum PosixSignals
* *
* libposix_define_errno to set the value of each PosixError * libposix_define_errno to set the value of each PosixError
* libposix_define_signal to set the value of each PosixSignal * 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_translate_error to translate error strings to PosixError
* libposix_set_signal_trampoline to dispatch signal received as notes * libposix_set_signal_trampoline to dispatch signal received as notes
* libposix_set_stat_reader * 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); 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 */ /* define the value of a specific PosixError according to the library headers */
extern int libposix_define_errno(PosixError e, int errno); extern int libposix_define_errno(PosixError e, int errno);

View File

@ -23,6 +23,7 @@
static PosixStatReader __libposix_stat_reader; static PosixStatReader __libposix_stat_reader;
static PosixOpenTranslator __libposix_open_translation; static PosixOpenTranslator __libposix_open_translation;
static int __libposix_AT_FDCWD;
typedef enum SeekTypes typedef enum SeekTypes
{ {
@ -409,14 +410,13 @@ FailWithError:
int int
POSIX_fchmodat(int *errnop, int fd, const char *path, long mode, int flag) 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; Dir *dir, ndir;
long cperm = 0; long cperm = 0;
char fullpath[4096], *p; char fullpath[4096], *p;
int l; int l;
PosixError e; PosixError e;
if(fd == AT_FDCWD){ if(fd == __libposix_AT_FDCWD){
return POSIX_chmod(errnop, path, mode); return POSIX_chmod(errnop, path, mode);
} else if(path == nil){ } else if(path == nil){
e = PosixENOENT; e = PosixENOENT;
@ -560,3 +560,12 @@ FailWithEIO:
*errnop = __libposix_get_errno(PosixEIO); *errnop = __libposix_get_errno(PosixEIO);
return -1; return -1;
} }
int
libposix_define_at_fdcwd(int AT_FDCWD)
{
if(__libposix_AT_FDCWD != 0)
return -1;
__libposix_AT_FDCWD = AT_FDCWD;
return 0;
}