1.0.10.31: sb-posix support for getgrnam and getgrgid
authorCyrus Harmon <ch-sbcl@bobobeach.com>
Sat, 6 Oct 2007 16:53:53 +0000 (16:53 +0000)
committerCyrus Harmon <ch-sbcl@bobobeach.com>
Sat, 6 Oct 2007 16:53:53 +0000 (16:53 +0000)
 * 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

contrib/sb-posix/constants.lisp
contrib/sb-posix/defpackage.lisp
contrib/sb-posix/interface.lisp
contrib/sb-posix/posix-tests.lisp
version.lisp-expr

index 3c753ff..5b4f65b 100644 (file)
@@ -21,6 +21,7 @@
  "errno.h"
  "dirent.h" "signal.h"
  #-win32 "pwd.h"
+ #-win32 "grp.h"
  "unistd.h"
  #-win32 "termios.h"
  #-win32 "syslog.h")
               #+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")
index f1137f7..91ee3c3 100644 (file)
@@ -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
index 155d84d..7bc574b 100644 (file)
 (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
index 2547728..9f74b51 100644 (file)
   (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
index 31368cd..ce2f991 100644 (file)
@@ -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"