From: Cyrus Harmon Date: Sat, 6 Oct 2007 16:53:53 +0000 (+0000) Subject: 1.0.10.31: sb-posix support for getgrnam and getgrgid X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=0b85642df140fabd8f0a91c85edff0543dc359b1;p=sbcl.git 1.0.10.31: sb-posix support for getgrnam and getgrgid * add alien-group and group protocol-class * add define-gr-call macro a la define-pw-call * alien definitions for getgrnam and getgrgid * trivial test for above calls --- diff --git a/contrib/sb-posix/constants.lisp b/contrib/sb-posix/constants.lisp index 3c753ff..5b4f65b 100644 --- a/contrib/sb-posix/constants.lisp +++ b/contrib/sb-posix/constants.lisp @@ -21,6 +21,7 @@ "errno.h" "dirent.h" "signal.h" #-win32 "pwd.h" + #-win32 "grp.h" "unistd.h" #-win32 "termios.h" #-win32 "syslog.h") @@ -290,6 +291,14 @@ #+nil (:integer fields "int" "pw_fields"))) + ;; group database + #-win32 + (:structure alien-group + ("struct group" + (c-string-pointer name "char *" "gr_name") + (c-string-pointer passwd "char *" "gr_passwd") + (gid-t gid "gid_t" "gr_gid"))) + (:structure alien-stat ("struct stat" (mode-t mode "mode_t" "st_mode") diff --git a/contrib/sb-posix/defpackage.lisp b/contrib/sb-posix/defpackage.lisp index f1137f7..91ee3c3 100644 --- a/contrib/sb-posix/defpackage.lisp +++ b/contrib/sb-posix/defpackage.lisp @@ -10,6 +10,7 @@ #:passwd-name #:passwd-passwd #:passwd-uid #:passwd-gid #:passwd-gecos #:passwd-dir #:passwd-shell + #:group-name #:group-gid #:group-passwd #:stat-mode #:stat-ino #:stat-dev #:stat-nlink #:stat-uid #:stat-gid #:stat-size #:stat-atime #:stat-mtime #:stat-ctime #:termios-iflag #:termios-oflag #:termios-cflag diff --git a/contrib/sb-posix/interface.lisp b/contrib/sb-posix/interface.lisp index 155d84d..7bc574b 100644 --- a/contrib/sb-posix/interface.lisp +++ b/contrib/sb-posix/interface.lisp @@ -404,6 +404,30 @@ (define-pw-call "getpwnam" login-name (function (* alien-passwd) c-string)) (define-pw-call "getpwuid" uid (function (* alien-passwd) uid-t)) +;;; group database +#-win32 +(define-protocol-class group alien-group () + ((name :initarg :name :accessor group-name) + (passwd :initarg :passwd :accessor group-passwd) + (gid :initarg :gid :accessor group-gid))) + +(defmacro define-gr-call (name arg type) + #-win32 + ;; FIXME: this isn't the documented way of doing this, surely? + (let ((lisp-name (intern (string-upcase name) :sb-posix))) + `(progn + (export ',lisp-name :sb-posix) + (declaim (inline ,lisp-name)) + (defun ,lisp-name (,arg) + (let ((r (alien-funcall (extern-alien ,name ,type) ,arg))) + (if (null r) + r + (alien-to-group r))))))) + +(define-gr-call "getgrnam" login-name (function (* alien-group) c-string)) +(define-gr-call "getgrgid" gid (function (* alien-group) gid-t)) + + #-win32 (define-protocol-class timeval alien-timeval () ((sec :initarg :tv-sec :accessor timeval-sec diff --git a/contrib/sb-posix/posix-tests.lisp b/contrib/sb-posix/posix-tests.lisp index 2547728..9f74b51 100644 --- a/contrib/sb-posix/posix-tests.lisp +++ b/contrib/sb-posix/posix-tests.lisp @@ -466,6 +466,18 @@ (not (sb-posix:getpwnam "root")) nil) +#-win32 +(deftest grent.1 + ;; make sure that we found something + (not (sb-posix:getgrgid 0)) + nil) + +#-win32 +(deftest grent.2 + ;; make sure that we found something + (not (sb-posix:getgrnam "wheel")) + nil) + #+nil ;; Requires root or special group + plus a sensible thing on the port (deftest cfget/setispeed.1 diff --git a/version.lisp-expr b/version.lisp-expr index 31368cd..ce2f991 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.10.30" +"1.0.10.31"