From 49da4de25cff93aa3761f730c8732cdca49feeec Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Mon, 18 Nov 2019 00:40:53 +0100 Subject: [PATCH] posix: POSIX_sysconf --- sys/include/posix.h | 19 ++++++++++++ sys/src/lib/posix/build.json | 2 ++ sys/src/lib/posix/sysconf.c | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 sys/src/lib/posix/sysconf.c diff --git a/sys/include/posix.h b/sys/include/posix.h index e0885ba..baa62a7 100644 --- a/sys/include/posix.h +++ b/sys/include/posix.h @@ -242,6 +242,24 @@ typedef enum PosixFDCmds PosixFDCSetFL } PosixFDCmds; +/* https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html + */ +typedef enum PosixSysConfNames +{ + /* Posix 1 */ + PosixSCNArgMax = 1, // _SC_ARG_MAX + PosixSCNChildMax, // _SC_CHILD_MAX + PosixSCNHostNameMax, // _SC_HOST_NAME_MAX + PosixSCNLoginNameMax, // _SC_LOGIN_NAME_MAX + PosixSCNClockTicks, // _SC_CLK_TCK + PosixSCNOpenMax, // _SC_OPEN_MAX + PosixSCNPageSize, // _SC_PAGESIZE + PosixSCNPosixVersion, // _SC_VERSION + + /* Posix 2 */ + PosixSCNLineMax // _SC_LINE_MAX +} PosixSysConfNames; + #endif /* _LIBPOSIX_DEF */ #ifndef _LIBPOSIX_H @@ -305,6 +323,7 @@ extern unsigned int POSIX_sleep(unsigned int seconds); extern int POSIX_pipe(int *errnop, int fildes[2]); extern int POSIX_umask(int *errnop, int mask); extern int POSIX_fcntl(int *errnop, int fd, PosixFDCmds cmd, uintptr_t arg); +extern long POSIX_sysconf(int *errnop, PosixSysConfNames name); extern int POSIX_sigaddset(int *errnop, PosixSignalMask *set, int signo); extern int POSIX_sigdelset(int *errnop, PosixSignalMask *set, int signo); diff --git a/sys/src/lib/posix/build.json b/sys/src/lib/posix/build.json index e960806..d53d6f1 100644 --- a/sys/src/lib/posix/build.json +++ b/sys/src/lib/posix/build.json @@ -1,6 +1,7 @@ { "LibPosix": { "Cflags": [ + "-DPORTABLE_SYSCALLS", "-DARCH=\"$ARCH\"", "-fasm", "-I." @@ -27,6 +28,7 @@ "sigqueue.c", "sigsets.c", "sigsuspend.c", + "sysconf.c", "termios.c", "timers.c" ] diff --git a/sys/src/lib/posix/sysconf.c b/sys/src/lib/posix/sysconf.c new file mode 100644 index 0000000..e697545 --- /dev/null +++ b/sys/src/lib/posix/sysconf.c @@ -0,0 +1,57 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2019 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 +#include "internal.h" + +long +POSIX_sysconf(int *errnop, PosixSysConfNames name) +{ + /* "arbitrary" means that no actual limit exists */ + + switch(name){ + case PosixSCNArgMax: // _SC_ARG_MAX + /* arbitrary */ + return 4096; + case PosixSCNChildMax: // _SC_CHILD_MAX + /* arbitrary */ + return 128; + case PosixSCNHostNameMax: // _SC_HOST_NAME_MAX + case PosixSCNLoginNameMax: // _SC_LOGIN_NAME_MAX + /* See Proc.genbuf in /sys/src/kern/port/portdat.h */ + return 128; + case PosixSCNClockTicks: // _SC_CLK_TCK + /* See HZ in /sys/src/kern/amd64/dat.h */ + return 100; + case PosixSCNOpenMax: // _SC_OPEN_MAX + /* arbitrary */ + return 256; + case PosixSCNPageSize: // _SC_PAGESIZE + return 4096; + case PosixSCNPosixVersion: // _SC_VERSION + return 200101; + case PosixSCNLineMax: // _SC_LINE_MAX + /* arbitrary */ + return 4096; + + default: + *errnop = __libposix_get_errno(PosixENOSYS); + return -1; + } +}