1.0.1.27: Add syslog(3) and friends to SB-POSIX.
[sbcl.git] / contrib / sb-posix / interface.lisp
index aef75cd..6d6d72c 100644 (file)
   (define-call "fchdir" int minusp (fd file-descriptor))
   (define-call "fchmod" int minusp (fd file-descriptor) (mode mode-t))
   (define-call "fchown" int minusp (fd file-descriptor)
-             (owner uid-t)  (group gid-t))
+               (owner uid-t)  (group gid-t))
   (define-call "fdatasync" int minusp (fd file-descriptor))
   (define-call ("ftruncate" :options :largefile)
       int minusp (fd file-descriptor) (length off-t))
       int minusp (pathname filename) (length off-t))
   ;; FIXME: Windows does have _mktemp, which has a slightlty different
   ;; interface
-  (define-call "mkstemp" int minusp (template c-string))
+  (defun mkstemp (template)
+    ;; we are emulating sb-alien's charset conversion for strings
+    ;; here, to accommodate for the call-by-reference nature of
+    ;; mkstemp's template strings.
+    (let ((arg (sb-ext:string-to-octets
+                (filename template)
+                :external-format sb-alien::*default-c-string-external-format*)))
+      (sb-sys:with-pinned-objects (arg)
+        (let ((result (alien-funcall (extern-alien "mkstemp"
+                                                   (function int c-string))
+                                     (sap-alien (sb-alien::vector-sap arg)
+                                                (* char)))))
+          (when (minusp result)
+            (syscall-error))
+          (values result
+                  (sb-ext:octets-to-string
+                   arg
+                   :external-format sb-alien::*default-c-string-external-format*))))))
   (define-call-internally ioctl-without-arg "ioctl" int minusp
                           (fd file-descriptor) (cmd int))
   (define-call-internally ioctl-with-int-arg "ioctl" int minusp
     (unless (null-alien r)
       (cast r c-string))))
 (define-call "putenv" int minusp (string c-string))
+
+;;; syslog
+#-win32
+(progn
+  (export 'openlog :sb-posix)
+  (export 'syslog :sb-posix)
+  (export 'closelog :sb-posix)
+  (defun openlog (ident options &optional (facility log-user))
+    (alien-funcall (extern-alien
+                    "openlog" (function void c-string int int))
+                   ident options facility))
+  (defun syslog (priority format &rest args)
+    "Send a message to the syslog facility, with severity level
+PRIORITY.  The message will be formatted as by CL:FORMAT (rather
+than C's printf) with format string FORMAT and arguments ARGS."
+    (flet ((syslog1 (priority message)
+             (alien-funcall (extern-alien
+                             "syslog" (function void int c-string c-string))
+                            priority "%s" message)))
+      (syslog1 priority (apply #'format nil format args))))
+  (define-call "closelog" void never-fails))
+