Commit ec45e3c756455506b345bc59449c3f6ac5c24bcf

Thomas de Grivel 2017-05-27T21:44:09

access, lseek

diff --git a/cffi-unistd.lisp b/cffi-unistd.lisp
index c151aec..9c08b55 100644
--- a/cffi-unistd.lisp
+++ b/cffi-unistd.lisp
@@ -1,6 +1,27 @@
 
 (in-package :cffi-unistd)
 
+(defcfun ("access" c-access) :int
+  (name :string)
+  (type :int))
+
+(defun access (name type)
+  (let ((r (c-access name type)))
+    (when (< r 0)
+      (error-errno "access"))
+    r))
+
+(defcfun ("lseek" c-lseek) off-t
+  (fd :int)
+  (offset off-t)
+  (whence :int))
+
+(defun lseek (fd offset whence)
+  (let ((r (c-lseek fd offset whence)))
+    (when (< r 0)
+      (error-errno "lseek"))
+    r))
+
 (defcfun ("close" c-close) :int
   (fd :int))
 
@@ -63,9 +84,11 @@ or number of bytes written otherwise."
 
 (defun pipe ()
   (with-foreign-object (fd :int 2)
-    (c-pipe fd)
-    (values (mem-aref fd :int 0)
-	    (mem-aref fd :int 1))))
+    (let ((r (c-pipe fd)))
+      (when (< r 0)
+	(error-errno "pipe"))
+      (values (mem-aref fd :int 0)
+	      (mem-aref fd :int 1)))))
 
 (defmacro with-pipe ((in-var out-var) &body body)
   `(multiple-value-bind (,in-var ,out-var) (pipe)
diff --git a/package.lisp b/package.lisp
index c13e9eb..9237c7e 100644
--- a/package.lisp
+++ b/package.lisp
@@ -12,6 +12,10 @@
    #:read
    #:write)
   (:export
+   #:c-access
+   #:access
+   #:c-lseek
+   #:lseek
    #:c-read
    #:read
    #:read-non-blocking