summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2018-10-12 18:10:53 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-10-21 13:39:52 +0100
commit301de4c825ae109cc3a7c780d662863ada62753b (patch)
tree6ec32101bff5b6b36603a4aa2b3a7cbcd26f1995
parent4e95fbccfbbec3c1ebc10dc156a154a2953200dd (diff)
downloadluxio-301de4c825ae109cc3a7c780d662863ada62753b.tar.bz2
Bind sysconf(3)
-rw-r--r--luxio.c14
-rw-r--r--luxio_constants.inc.in132
-rw-r--r--tests/test-sysconf.lua10
3 files changed, 130 insertions, 26 deletions
diff --git a/luxio.c b/luxio.c
index 6507a00..97323f1 100644
--- a/luxio.c
+++ b/luxio.c
@@ -1011,7 +1011,17 @@ luxio_isatty(lua_State *L)
/* 4.8 Configurable system variables *****************************************/
-/* TODO: sysconf() 4.8.1 */
+static int
+luxio_sysconf(lua_State *L)
+{
+ int name = luaL_checkinteger(L, 1);
+ long result = sysconf(name);
+
+ lua_pushinteger(L, result);
+ lua_pushinteger(L, result == -1 ? errno : 0);
+
+ return 2;
+}
/*** Directories.
@section dir
@@ -4592,6 +4602,8 @@ luxio_functions[] = {
{ "ttyname", luxio_ttyname },
{ "isatty", luxio_isatty },
+ { "sysconf", luxio_sysconf },
+
{ NULL, NULL }
};
diff --git a/luxio_constants.inc.in b/luxio_constants.inc.in
index ca045da..9a5513b 100644
--- a/luxio_constants.inc.in
+++ b/luxio_constants.inc.in
@@ -83,7 +83,7 @@ static const struct {
/* stat file types */
E(S_IFMT),
? E(S_IFSOCK),
-? E(S_IFLNK),
+? E(S_IFLNK),
E(S_IFREG),
E(S_IFBLK),
E(S_IFDIR),
@@ -100,21 +100,21 @@ static const struct {
E(F_GETFD), E(F_SETFD), E(F_GETFL), E(F_SETFL), E(F_DUPFD),
? E(F_DUPFD_CLOEXEC),
? E(F_SETPIPE_SZ),
-? E(F_GETPIPE_SZ),
+? E(F_GETPIPE_SZ),
E(F_SETLK),
E(F_SETLKW),
E(F_GETLK),
E(F_RDLCK),
E(F_WRLCK),
E(F_UNLCK),
-
- /* posix_fadvise advice types */
-? E(POSIX_FADV_NORMAL),
-? E(POSIX_FADV_SEQUENTIAL),
-? E(POSIX_FADV_RANDOM),
-? E(POSIX_FADV_NOREUSE),
-? E(POSIX_FADV_WILLNEED),
-? E(POSIX_FADV_DONTNEED),
+
+ /* posix_fadvise advice types */
+? E(POSIX_FADV_NORMAL),
+? E(POSIX_FADV_SEQUENTIAL),
+? E(POSIX_FADV_RANDOM),
+? E(POSIX_FADV_NOREUSE),
+? E(POSIX_FADV_WILLNEED),
+? E(POSIX_FADV_DONTNEED),
/* socket types */
E(PF_UNSPEC),
@@ -173,20 +173,20 @@ static const struct {
E(AI_CANONNAME),
E(AI_PASSIVE),
-? E(MSG_CONFIRM),
-? E(MSG_DONTROUTE),
-? E(MSG_DONTWAIT),
-? E(MSG_EOR),
-? E(MSG_MORE),
-? E(MSG_NOSIGNAL),
-? E(MSG_OOB),
-? E(MSG_CMSG_CLOEXEC),
-? E(MSG_ERRQUEUE),
-? E(MSG_PEEK),
-? E(MSG_TRUNC),
-? E(MSG_WAITALL),
-
- /* poll-related defines */
+? E(MSG_CONFIRM),
+? E(MSG_DONTROUTE),
+? E(MSG_DONTWAIT),
+? E(MSG_EOR),
+? E(MSG_MORE),
+? E(MSG_NOSIGNAL),
+? E(MSG_OOB),
+? E(MSG_CMSG_CLOEXEC),
+? E(MSG_ERRQUEUE),
+? E(MSG_PEEK),
+? E(MSG_TRUNC),
+? E(MSG_WAITALL),
+
+ /* poll-related defines */
E(POLLIN),
E(POLLPRI),
E(POLLOUT),
@@ -233,7 +233,7 @@ static const struct {
? E(SIGTSTP),
? E(SIGTTIN),
? E(SIGTTOU),
- /* SUSv2/POSIX.1-2001 */
+ /* SUSv2/POSIX.1-2001 */
? E(SIGBUS),
? E(SIGPOLL),
? E(SIGIO),
@@ -339,6 +339,88 @@ static const struct {
E(EXIT_SUCCESS),
E(EXIT_FAILURE),
+ /* sysconf variables */
+ E(_SC_AIO_LISTIO_MAX),
+ E(_SC_AIO_MAX),
+ E(_SC_AIO_PRIO_DELTA_MAX),
+ E(_SC_ARG_MAX),
+ E(_SC_ATEXIT_MAX),
+ E(_SC_BC_BASE_MAX),
+ E(_SC_BC_DIM_MAX),
+ E(_SC_BC_SCALE_MAX),
+ E(_SC_BC_STRING_MAX),
+ E(_SC_CHILD_MAX),
+ E(_SC_CLK_TCK),
+ E(_SC_COLL_WEIGHTS_MAX),
+ E(_SC_DELAYTIMER_MAX),
+ E(_SC_EXPR_NEST_MAX),
+ E(_SC_HOST_NAME_MAX),
+ E(_SC_IOV_MAX),
+ E(_SC_LINE_MAX),
+ E(_SC_LOGIN_NAME_MAX),
+ E(_SC_NGROUPS_MAX),
+ E(_SC_GETGR_R_SIZE_MAX),
+ E(_SC_GETPW_R_SIZE_MAX),
+ E(_SC_MQ_OPEN_MAX),
+ E(_SC_MQ_PRIO_MAX),
+ E(_SC_OPEN_MAX),
+ E(_SC_ADVISORY_INFO),
+ E(_SC_BARRIERS),
+ E(_SC_ASYNCHRONOUS_IO),
+ E(_SC_CLOCK_SELECTION),
+ E(_SC_CPUTIME),
+ E(_SC_FSYNC),
+ E(_SC_IPV6),
+ E(_SC_JOB_CONTROL),
+ E(_SC_MAPPED_FILES),
+ E(_SC_MEMLOCK),
+ E(_SC_MEMLOCK_RANGE),
+ E(_SC_MEMORY_PROTECTION),
+ E(_SC_MESSAGE_PASSING),
+ E(_SC_MONOTONIC_CLOCK),
+ E(_SC_PRIORITIZED_IO),
+ E(_SC_PRIORITY_SCHEDULING),
+ E(_SC_RAW_SOCKETS),
+ E(_SC_READER_WRITER_LOCKS),
+ E(_SC_REALTIME_SIGNALS),
+ E(_SC_REGEXP),
+ E(_SC_SAVED_IDS),
+ E(_SC_SEMAPHORES),
+ E(_SC_SHARED_MEMORY_OBJECTS),
+ E(_SC_SHELL),
+ E(_SC_SPAWN),
+ E(_SC_SPIN_LOCKS),
+ E(_SC_SPORADIC_SERVER),
+ E(_SC_SS_REPL_MAX),
+ E(_SC_SYNCHRONIZED_IO),
+ E(_SC_THREAD_ATTR_STACKADDR),
+ E(_SC_THREAD_CPUTIME),
+ E(_SC_THREAD_PRIO_INHERIT),
+ E(_SC_THREAD_PRIO_PROTECT),
+ E(_SC_THREAD_PRIORITY_SCHEDULING),
+ E(_SC_THREAD_PROCESS_SHARED),
+ E(_SC_THREAD_ROBUST_PRIO_INHERIT),
+ E(_SC_THREAD_ROBUST_PRIO_PROTECT),
+ E(_SC_THREAD_SAFE_FUNCTIONS),
+ E(_SC_THREAD_SPORADIC_SERVER),
+ E(_SC_THREADS),
+ E(_SC_TIMEOUTS),
+ E(_SC_TIMERS),
+ E(_SC_TRACE),
+ E(_SC_TRACE_EVENT_FILTER),
+ E(_SC_TRACE_EVENT_NAME_MAX),
+ E(_SC_TRACE_INHERIT),
+ E(_SC_TRACE_LOG),
+ E(_SC_TRACE_NAME_MAX),
+ E(_SC_TRACE_SYS_MAX),
+ E(_SC_TRACE_USER_EVENT_MAX),
+ E(_SC_TYPED_MEMORY_OBJECTS),
+ E(_SC_VERSION),
+ E(_SC_V7_ILP32_OFF32),
+ E(_SC_V7_ILP32_OFFBIG),
+ E(_SC_V7_LP64_OFF64),
+ E(_SC_V7_LPBIG_OFFBIG),
+
{ NULL, 0 }
};
diff --git a/tests/test-sysconf.lua b/tests/test-sysconf.lua
new file mode 100644
index 0000000..cba7f1e
--- /dev/null
+++ b/tests/test-sysconf.lua
@@ -0,0 +1,10 @@
+local l = require "luxio"
+local io = require "io"
+
+print(l.sysconf(l._SC_ARG_MAX))
+
+n, errno = l.sysconf(-1)
+if n == -1 then
+ io.stderr:write(("sysconf: %s\n"):format(l.strerror(errno)))
+ os.exit(l.EXIT_FAILURE)
+end