changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/std/os.lisp

changeset 698: 96958d3eb5b0
parent: ebe3315b7add
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; std/os.lisp --- OS interop definitions
2 
3 ;; UNIX only.
4 
5 ;;; Code:
6 (in-package :std/os)
7 (require 'sb-posix)
8 
9 (defun list-all-users ()
10  "List all users via passwd. (uid gid name home shell comment)"
11  (let ((r nil))
12  (sb-posix:do-passwds (u r)
13  (push (list (sb-posix:passwd-uid u)
14  (sb-posix:passwd-gid u)
15  (sb-posix:passwd-name u)
16  (sb-posix:passwd-dir u)
17  (sb-posix:passwd-shell u)
18  (sb-posix:passwd-gecos u))
19  r))
20  r))
21 
22 (defun list-all-groups ()
23  "List all groups. (gid name mem)"
24  (let ((r nil))
25  (sb-posix:do-groups (g r) (push (list (sb-posix:group-gid g)
26  (sb-posix:group-name g)
27  (sb-posix:group-mem g))
28  r))))
29 
30 (defmacro with-umask (mask &body body)
31  "Temporarily set the system-wide umask for the extent of BODY."
32  (with-gensyms (umask)
33  `(let ((,umask (sb-posix:umask ,mask)))
34  (unwind-protect (progn ,@body)
35  (sb-posix:umask ,umask)))))
36 
37 ;; (with-umask #o22 nil)
38 
39 (defmacro with-fd ((fvar fname &key (flags #.sb-posix:o-rdonly) (close t)) &body body)
40  `(let* ((,fvar (sb-posix:open ,fname ,flags)))
41  (unwind-protect (progn ,@body)
42  ,@(when close `(sb-posix:close ,fvar)))))