FWIW... and I apologize if this is a bit long with all of the code
snippets but I thought maybe somebody might find it useful <shrug>...
I'm loading the following in my .cmucl-init.lisp for the moment.
;;;; file: cmucl-unix-patches.lisp
(in-package #:unix)
(without-package-locks
(defun unix-getgrgid (gid)
"Return a GROUP-INFO structure for the group identified by GID, or
NIL if not found."
(declare (type unix-gid gid))
(let ((buf-size (alien:alien-funcall
(alien:extern-alien "sysconf"
(function c-call:long
c-call:int))
+sc-getgr-r-size-max+)))
(with-alien ((buf (array c-call:char
;; Using sysconf to get the size
#.(alien:alien-funcall
(alien:extern-alien "sysconf"
(function
c-call:long
c-call:int))
+sc-getgr-r-size-max+)))
(group-info (struct group)))
(let ((result (alien-funcall
(extern-alien "getgrgid_r"
(function (* (struct group))
c-call:unsigned-int
(* (struct group))
(* c-call:char)
c-call:unsigned-int))
gid
(addr group-info)
(cast buf (* c-call:char))
buf-size)))
(unless (zerop (sap-int (alien-sap result)))
(make-group-info
:name (string (cast (slot result 'gr-name)
c-call:c-string))
:password (string (cast (slot result 'gr-passwd)
c-call:c-string))
:gid (slot result 'gr-gid)
:members (loop :with members = (slot result 'gr-mem)
:for i :from 0
:for member = (deref members i)
:until (zerop (sap-int (alien-sap member)))
:collect (string
(cast member
c-call:c-string))))))))))
I'm getting the constatns from the following:
;;;; file: cmucl-unix-constants.lisp
(in-package #:unix)
(without-package-locks
(defconstant +sc-arg-max+ 1)
(defconstant +sc-child-max+ 2)
#| ... elided for brevity ... |#
(defconstant +sc-getgr-r-size-max+ 569)
#| ... #|)
Which I generated from, more or less, the following:
#include <stdio.h>
#include <unistd.h>
int main()
{
#ifdef _SC_ARG_MAX
printf("(defconstant +sc-arg-max+ %d)\n", _SC_ARG_MAX);
#endif
#ifdef _SC_CHILD_MAX
printf("(defconstant +sc-child-max+ %d)\n", _SC_CHILD_MAX);
#endif
#ifdef _SC_CLK_TCK
printf("(defconstant +sc-clk-tck+ %d)\n", _SC_CLK_TCK);
#endif
#ifdef _SC_NGROUPS_MAX
printf("(defconstant +sc-ngroups-max+ %d)\n", _SC_NGROUPS_MAX);
#endif
#ifdef _SC_OPEN_MAX
printf("(defconstant +sc-open-max+ %d)\n", _SC_OPEN_MAX);
#endif
#ifdef _SC_JOB_CONTROL
printf("(defconstant +sc-job-control+ %d)\n", _SC_JOB_CONTROL);
#endif
#ifdef _SC_SAVED_IDS
printf("(defconstant +sc-saved-ids+ %d)\n", _SC_SAVED_IDS);
#endif
#ifdef _SC_VERSION
printf("(defconstant +sc-version+ %d)\n", _SC_VERSION);
#endif
#ifdef _SC_PASS_MAX
printf("(defconstant +sc-pass-max+ %d)\n", _SC_PASS_MAX);
#endif
#ifdef _SC_LOGNAME_MAX
printf("(defconstant +sc-logname-max+ %d)\n", _SC_LOGNAME_MAX);
#endif
#ifdef _SC_PAGESIZE
printf("(defconstant +sc-pagesize+ %d)\n", _SC_PAGESIZE);
#endif
#ifdef _SC_XOPEN_VERSION
printf("(defconstant +sc-xopen-version+ %d)\n", _SC_XOPEN_VERSION);
#endif
#ifdef _SC_NPROCESSORS_CONF
printf("(defconstant +sc-nprocessors-conf+ %d)\n",
_SC_NPROCESSORS_CONF);
#endif
#ifdef _SC_NPROCESSORS_ONLN
printf("(defconstant +sc-nprocessors-onln+ %d)\n",
_SC_NPROCESSORS_ONLN);
#endif
#ifdef _SC_STREAM_MAX
printf("(defconstant +sc-stream-max+ %d)\n", _SC_STREAM_MAX);
#endif
#ifdef _SC_TZNAME_MAX
printf("(defconstant +sc-tzname-max+ %d)\n", _SC_TZNAME_MAX);
#endif
#ifdef _SC_AIO_LISTIO_MAX
printf("(defconstant +sc-aio-listio-max+ %d)\n", _SC_AIO_LISTIO_MAX);
#endif
#ifdef _SC_AIO_MAX
printf("(defconstant +sc-aio-max+ %d)\n", _SC_AIO_MAX);
#endif
#ifdef _SC_AIO_PRIO_DELTA_MAX
printf("(defconstant +sc-aio-prio-delta-max+ %d)\n",
_SC_AIO_PRIO_DELTA_MAX);
#endif
#ifdef _SC_ASYNCHRONOUS_IO
printf("(defconstant +sc-asynchronous-io+ %d)\n", _SC_ASYNCHRONOUS_IO);
#endif
#ifdef _SC_DELAYTIMER_MAX
printf("(defconstant +sc-delaytimer-max+ %d)\n", _SC_DELAYTIMER_MAX);
#endif
#ifdef _SC_FSYNC
printf("(defconstant +sc-fsync+ %d)\n", _SC_FSYNC);
#endif
#ifdef _SC_MAPPED_FILES
printf("(defconstant +sc-mapped-files+ %d)\n", _SC_MAPPED_FILES);
#endif
#ifdef _SC_MEMLOCK
printf("(defconstant +sc-memlock+ %d)\n", _SC_MEMLOCK);
#endif
#ifdef _SC_MEMLOCK_RANGE
printf("(defconstant +sc-memlock-range+ %d)\n", _SC_MEMLOCK_RANGE);
#endif
#ifdef _SC_MEMORY_PROTECTION
printf("(defconstant +sc-memory-protection+ %d)\n",
_SC_MEMORY_PROTECTION);
#endif
#ifdef _SC_MESSAGE_PASSING
printf("(defconstant +sc-message-passing+ %d)\n", _SC_MESSAGE_PASSING);
#endif
#ifdef _SC_MQ_OPEN_MAX
printf("(defconstant +sc-mq-open-max+ %d)\n", _SC_MQ_OPEN_MAX);
#endif
#ifdef _SC_MQ_PRIO_MAX
printf("(defconstant +sc-mq-prio-max+ %d)\n", _SC_MQ_PRIO_MAX);
#endif
#ifdef _SC_PRIORITIZED_IO
printf("(defconstant +sc-prioritized-io+ %d)\n", _SC_PRIORITIZED_IO);
#endif
#ifdef _SC_PRIORITY_SCHEDULING
printf("(defconstant +sc-priority-scheduling+ %d)\n",
_SC_PRIORITY_SCHEDULING);
#endif
#ifdef _SC_REALTIME_SIGNALS
printf("(defconstant +sc-realtime-signals+ %d)\n",
_SC_REALTIME_SIGNALS);
#endif
#ifdef _SC_RTSIG_MAX
printf("(defconstant +sc-rtsig-max+ %d)\n", _SC_RTSIG_MAX);
#endif
#ifdef _SC_SEMAPHORES
printf("(defconstant +sc-semaphores+ %d)\n", _SC_SEMAPHORES);
#endif
#ifdef _SC_SEM_NSEMS_MAX
printf("(defconstant +sc-sem-nsems-max+ %d)\n", _SC_SEM_NSEMS_MAX);
#endif
#ifdef _SC_SEM_VALUE_MAX
printf("(defconstant +sc-sem-value-max+ %d)\n", _SC_SEM_VALUE_MAX);
#endif
#ifdef _SC_SHARED_MEMORY_OBJECTS
printf("(defconstant +sc-shared-memory-objects+ %d)\n",
_SC_SHARED_MEMORY_OBJECTS);
#endif
#ifdef _SC_SIGQUEUE_MAX
printf("(defconstant +sc-sigqueue-max+ %d)\n", _SC_SIGQUEUE_MAX);
#endif
#ifdef _SC_SIGRT_MIN
printf("(defconstant +sc-sigrt-min+ %d)\n", _SC_SIGRT_MIN);
#endif
#ifdef _SC_SIGRT_MAX
printf("(defconstant +sc-sigrt-max+ %d)\n", _SC_SIGRT_MAX);
#endif
#ifdef _SC_SYNCHRONIZED_IO
printf("(defconstant +sc-synchronized-io+ %d)\n", _SC_SYNCHRONIZED_IO);
#endif
#ifdef _SC_TIMERS
printf("(defconstant +sc-timers+ %d)\n", _SC_TIMERS);
#endif
#ifdef _SC_TIMER_MAX
printf("(defconstant +sc-timer-max+ %d)\n", _SC_TIMER_MAX);
#endif
#ifdef _SC_2_C_BIND
printf("(defconstant +sc-2-c-bind+ %d)\n", _SC_2_C_BIND);
#endif
#ifdef _SC_2_C_DEV
printf("(defconstant +sc-2-c-dev+ %d)\n", _SC_2_C_DEV);
#endif
#ifdef _SC_2_C_VERSION
printf("(defconstant +sc-2-c-version+ %d)\n", _SC_2_C_VERSION);
#endif
#ifdef _SC_2_FORT_DEV
printf("(defconstant +sc-2-fort-dev+ %d)\n", _SC_2_FORT_DEV);
#endif
#ifdef _SC_2_FORT_RUN
printf("(defconstant +sc-2-fort-run+ %d)\n", _SC_2_FORT_RUN);
#endif
#ifdef _SC_2_LOCALEDEF
printf("(defconstant +sc-2-localedef+ %d)\n", _SC_2_LOCALEDEF);
#endif
#ifdef _SC_2_SW_DEV
printf("(defconstant +sc-2-sw-dev+ %d)\n", _SC_2_SW_DEV);
#endif
#ifdef _SC_2_UPE
printf("(defconstant +sc-2-upe+ %d)\n", _SC_2_UPE);
#endif
#ifdef _SC_2_VERSION
printf("(defconstant +sc-2-version+ %d)\n", _SC_2_VERSION);
#endif
#ifdef _SC_BC_BASE_MAX
printf("(defconstant +sc-bc-base-max+ %d)\n", _SC_BC_BASE_MAX);
#endif
#ifdef _SC_BC_DIM_MAX
printf("(defconstant +sc-bc-dim-max+ %d)\n", _SC_BC_DIM_MAX);
#endif
#ifdef _SC_BC_SCALE_MAX
printf("(defconstant +sc-bc-scale-max+ %d)\n", _SC_BC_SCALE_MAX);
#endif
#ifdef _SC_BC_STRING_MAX
printf("(defconstant +sc-bc-string-max+ %d)\n", _SC_BC_STRING_MAX);
#endif
#ifdef _SC_COLL_WEIGHTS_MAX
printf("(defconstant +sc-coll-weights-max+ %d)\n",
_SC_COLL_WEIGHTS_MAX);
#endif
#ifdef _SC_EXPR_NEST_MAX
printf("(defconstant +sc-expr-nest-max+ %d)\n", _SC_EXPR_NEST_MAX);
#endif
#ifdef _SC_LINE_MAX
printf("(defconstant +sc-line-max+ %d)\n", _SC_LINE_MAX);
#endif
#ifdef _SC_RE_DUP_MAX
printf("(defconstant +sc-re-dup-max+ %d)\n", _SC_RE_DUP_MAX);
#endif
#ifdef _SC_XOPEN_CRYPT
printf("(defconstant +sc-xopen-crypt+ %d)\n", _SC_XOPEN_CRYPT);
#endif
#ifdef _SC_XOPEN_ENH_I18N
printf("(defconstant +sc-xopen-enh-i18n+ %d)\n", _SC_XOPEN_ENH_I18N);
#endif
#ifdef _SC_XOPEN_SHM
printf("(defconstant +sc-xopen-shm+ %d)\n", _SC_XOPEN_SHM);
#endif
#ifdef _SC_2_CHAR_TERM
printf("(defconstant +sc-2-char-term+ %d)\n", _SC_2_CHAR_TERM);
#endif
#ifdef _SC_XOPEN_XCU_VERSION
printf("(defconstant +sc-xopen-xcu-version+ %d)\n",
_SC_XOPEN_XCU_VERSION);
#endif
#ifdef _SC_ATEXIT_MAX
printf("(defconstant +sc-atexit-max+ %d)\n", _SC_ATEXIT_MAX);
#endif
#ifdef _SC_IOV_MAX
printf("(defconstant +sc-iov-max+ %d)\n", _SC_IOV_MAX);
#endif
#ifdef _SC_XOPEN_UNIX
printf("(defconstant +sc-xopen-unix+ %d)\n", _SC_XOPEN_UNIX);
#endif
#ifdef _SC_PAGE_SIZE
printf("(defconstant +sc-page-size+ %d)\n", _SC_PAGE_SIZE);
#endif
#ifdef _SC_T_IOV_MAX
printf("(defconstant +sc-t-iov-max+ %d)\n", _SC_T_IOV_MAX);
#endif
#ifdef _SC_PHYS_PAGES
printf("(defconstant +sc-phys-pages+ %d)\n", _SC_PHYS_PAGES);
#endif
#ifdef _SC_AVPHYS_PAGES
printf("(defconstant +sc-avphys-pages+ %d)\n", _SC_AVPHYS_PAGES);
#endif
#ifdef _SC_COHER_BLKSZ
printf("(defconstant +sc-coher-blksz+ %d)\n", _SC_COHER_BLKSZ);
#endif
#ifdef _SC_SPLIT_CACHE
printf("(defconstant +sc-split-cache+ %d)\n", _SC_SPLIT_CACHE);
#endif
#ifdef _SC_ICACHE_SZ
printf("(defconstant +sc-icache-sz+ %d)\n", _SC_ICACHE_SZ);
#endif
#ifdef _SC_DCACHE_SZ
printf("(defconstant +sc-dcache-sz+ %d)\n", _SC_DCACHE_SZ);
#endif
#ifdef _SC_ICACHE_LINESZ
printf("(defconstant +sc-icache-linesz+ %d)\n", _SC_ICACHE_LINESZ);
#endif
#ifdef _SC_DCACHE_LINESZ
printf("(defconstant +sc-dcache-linesz+ %d)\n", _SC_DCACHE_LINESZ);
#endif
#ifdef _SC_ICACHE_BLKSZ
printf("(defconstant +sc-icache-blksz+ %d)\n", _SC_ICACHE_BLKSZ);
#endif
#ifdef _SC_DCACHE_BLKSZ
printf("(defconstant +sc-dcache-blksz+ %d)\n", _SC_DCACHE_BLKSZ);
#endif
#ifdef _SC_DCACHE_TBLKSZ
printf("(defconstant +sc-dcache-tblksz+ %d)\n", _SC_DCACHE_TBLKSZ);
#endif
#ifdef _SC_ICACHE_ASSOC
printf("(defconstant +sc-icache-assoc+ %d)\n", _SC_ICACHE_ASSOC);
#endif
#ifdef _SC_DCACHE_ASSOC
printf("(defconstant +sc-dcache-assoc+ %d)\n", _SC_DCACHE_ASSOC);
#endif
#ifdef _SC_MAXPID
printf("(defconstant +sc-maxpid+ %d)\n", _SC_MAXPID);
#endif
#ifdef _SC_STACK_PROT
printf("(defconstant +sc-stack-prot+ %d)\n", _SC_STACK_PROT);
#endif
#ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS
printf("(defconstant +sc-thread-destructor-iterations+ %d)\n",
_SC_THREAD_DESTRUCTOR_ITERATIONS);
#endif
#ifdef _SC_GETGR_R_SIZE_MAX
printf("(defconstant +sc-getgr-r-size-max+ %d)\n",
_SC_GETGR_R_SIZE_MAX);
#endif
#ifdef _SC_GETPW_R_SIZE_MAX
printf("(defconstant +sc-getpw-r-size-max+ %d)\n",
_SC_GETPW_R_SIZE_MAX);
#endif
#ifdef _SC_LOGIN_NAME_MAX
printf("(defconstant +sc-login-name-max+ %d)\n", _SC_LOGIN_NAME_MAX);
#endif
#ifdef _SC_THREAD_KEYS_MAX
printf("(defconstant +sc-thread-keys-max+ %d)\n", _SC_THREAD_KEYS_MAX);
#endif
#ifdef _SC_THREAD_STACK_MIN
printf("(defconstant +sc-thread-stack-min+ %d)\n",
_SC_THREAD_STACK_MIN);
#endif
#ifdef _SC_THREAD_THREADS_MAX
printf("(defconstant +sc-thread-threads-max+ %d)\n",
_SC_THREAD_THREADS_MAX);
#endif
#ifdef _SC_TTY_NAME_MAX
printf("(defconstant +sc-tty-name-max+ %d)\n", _SC_TTY_NAME_MAX);
#endif
#ifdef _SC_THREADS
printf("(defconstant +sc-threads+ %d)\n", _SC_THREADS);
#endif
#ifdef _SC_THREAD_ATTR_STACKADDR
printf("(defconstant +sc-thread-attr-stackaddr+ %d)\n",
_SC_THREAD_ATTR_STACKADDR);
#endif
#ifdef _SC_THREAD_ATTR_STACKSIZE
printf("(defconstant +sc-thread-attr-stacksize+ %d)\n",
_SC_THREAD_ATTR_STACKSIZE);
#endif
#ifdef _SC_THREAD_PRIORITY_SCHEDULING
printf("(defconstant +sc-thread-priority-scheduling+ %d)\n",
_SC_THREAD_PRIORITY_SCHEDULING);
#endif
#ifdef _SC_THREAD_PRIO_INHERIT
printf("(defconstant +sc-thread-prio-inherit+ %d)\n",
_SC_THREAD_PRIO_INHERIT);
#endif
#ifdef _SC_THREAD_PRIO_PROTECT
printf("(defconstant +sc-thread-prio-protect+ %d)\n",
_SC_THREAD_PRIO_PROTECT);
#endif
#ifdef _SC_THREAD_PROCESS_SHARED
printf("(defconstant +sc-thread-process-shared+ %d)\n",
_SC_THREAD_PROCESS_SHARED);
#endif
#ifdef _SC_THREAD_SAFE_FUNCTIONS
printf("(defconstant +sc-thread-safe-functions+ %d)\n",
_SC_THREAD_SAFE_FUNCTIONS);
#endif
#ifdef _SC_XOPEN_LEGACY
printf("(defconstant +sc-xopen-legacy+ %d)\n", _SC_XOPEN_LEGACY);
#endif
#ifdef _SC_XOPEN_REALTIME
printf("(defconstant +sc-xopen-realtime+ %d)\n", _SC_XOPEN_REALTIME);
#endif
#ifdef _SC_XOPEN_REALTIME_THREADS
printf("(defconstant +sc-xopen-realtime-threads+ %d)\n",
_SC_XOPEN_REALTIME_THREADS);
#endif
#ifdef _SC_XBS5_ILP32_OFF32
printf("(defconstant +sc-xbs5-ilp32-off32+ %d)\n",
_SC_XBS5_ILP32_OFF32);
#endif
#ifdef _SC_XBS5_ILP32_OFFBIG
printf("(defconstant +sc-xbs5-ilp32-offbig+ %d)\n",
_SC_XBS5_ILP32_OFFBIG);
#endif
#ifdef _SC_XBS5_LP64_OFF64
printf("(defconstant +sc-xbs5-lp64-off64+ %d)\n", _SC_XBS5_LP64_OFF64);
#endif
#ifdef _SC_XBS5_LPBIG_OFFBIG
printf("(defconstant +sc-xbs5-lpbig-offbig+ %d)\n",
_SC_XBS5_LPBIG_OFFBIG);
#endif
#ifdef _PC_LINK_MAX
printf("(defconstant +pc-link-max+ %d)\n", _PC_LINK_MAX);
#endif
#ifdef _PC_MAX_CANON
printf("(defconstant +pc-max-canon+ %d)\n", _PC_MAX_CANON);
#endif
#ifdef _PC_MAX_INPUT
printf("(defconstant +pc-max-input+ %d)\n", _PC_MAX_INPUT);
#endif
#ifdef _PC_NAME_MAX
printf("(defconstant +pc-name-max+ %d)\n", _PC_NAME_MAX);
#endif
#ifdef _PC_PATH_MAX
printf("(defconstant +pc-path-max+ %d)\n", _PC_PATH_MAX);
#endif
#ifdef _PC_PIPE_BUF
printf("(defconstant +pc-pipe-buf+ %d)\n", _PC_PIPE_BUF);
#endif
#ifdef _PC_NO_TRUNC
printf("(defconstant +pc-no-trunc+ %d)\n", _PC_NO_TRUNC);
#endif
#ifdef _PC_VDISABLE
printf("(defconstant +pc-vdisable+ %d)\n", _PC_VDISABLE);
#endif
#ifdef _PC_CHOWN_RESTRICTED
printf("(defconstant +pc-chown-restricted+ %d)\n",
_PC_CHOWN_RESTRICTED);
#endif
#ifdef _PC_ASYNC_IO
printf("(defconstant +pc-async-io+ %d)\n", _PC_ASYNC_IO);
#endif
#ifdef _PC_PRIO_IO
printf("(defconstant +pc-prio-io+ %d)\n", _PC_PRIO_IO);
#endif
#ifdef _PC_SYNC_IO
printf("(defconstant +pc-sync-io+ %d)\n", _PC_SYNC_IO);
#endif
}
--
Damien Kick