1.0.47.5: sb-posix: add read(2) and write(2)
authorNikodemus Siivola <nikodemus@random-state.net>
Wed, 30 Mar 2011 16:48:49 +0000 (16:48 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Wed, 30 Mar 2011 16:48:49 +0000 (16:48 +0000)
  Patch by Daniel Lowe.

  Also add missing NEWS entries.

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

diff --git a/NEWS b/NEWS
index 89d2128..3a71c91 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,11 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
+changes relative to sbcl-1.0.47:
+  * enhancement: read() and write() have been added to SB-POSIX.
+  * enhancement: types of DEFSTRUCT constructors are proclaimed more
+    accurately, allowing better typechecking of call-sites.
+  * bug fix: TRACE behaves better when attempting to trace undefined
+    functions. (lp#740717)
+
 changes in sbcl-1.0.47 relative to sbcl-1.0.46:
   * bug fix: fix mach port rights leaks in mach exception handling code on
     darwin/x86 and /x86-64. (thanks to Willem Oudshoorn for motivation and the
index 6764657..9c0ce34 100644 (file)
@@ -8,31 +8,28 @@ in this list does _not_ imply we've definitely decided something needs
 adding.
 
 FD_CLR FD_ISSET FD_SET FD_ZERO accept acct adjtime adjtimex bdflush
-bind break brk cacheflush capget capset clone connect
-create_module delete_module execve exit flock
-fstatfs ftime getcontext getdents getdomainname
-getdtablesize getgroups gethostid gethostname getitimer 
+bind break brk cacheflush capget capset clone connect create_module
+delete_module execve exit flock fstatfs ftime getcontext getdents
+getdomainname getdtablesize getgroups gethostid gethostname getitimer
 getpeername getpriority getrlimit getrusage getsockname getsockopt
 gettimeofday gtty idle init_module ioctl_list ioperm iopl listen
-llseek lock madvise mincore mknod mlock
-modify_ldt mount mprotect mpx mremap msgctl msgget msgop msgrcv msgsnd
-munlock nanosleep nice pause poll
-prctl pread prof profil pselect ptrace pwrite query_module quotactl
-read readv reboot recv recvfrom recvmsg
-sbrk sched_get_priority_max sched_get_priority_min sched_getparam
+llseek lock madvise mincore mknod mlock modify_ldt mount mprotect mpx
+mremap msgctl msgget msgop msgrcv msgsnd munlock nanosleep nice pause
+poll prctl pread prof profil pselect ptrace pwrite query_module
+quotactl readv reboot recv recvfrom recvmsg sbrk
+sched_get_priority_max sched_get_priority_min sched_getparam
 sched_getscheduler sched_rr_get_interval sched_setparam
 sched_setscheduler sched_yield select semctl semget semop send
 sendfile sendmsg sendto setcontext setdomainname setgroups sethostid
-sethostname setitimer setpriority setrlimit setsockopt
-settimeofday sgetmask shmat shmctl shmdt shmget shmop shutdown
-sigaction sigaltstack sigblock siggetmask sigmask signal sigpause
-sigpending sigprocmask sigreturn sigsetmask sigsuspend sigvec socket
-socketcall socketpair ssetmask statfs stime stty swapoff swapon
-syscalls sysctl sysfs sysinfo times
-ulimit umount uname ustat vfork vhangup wait3
-wait4 write writev
-
-4) In the spec but not implemented: 
+sethostname setitimer setpriority setrlimit setsockopt settimeofday
+sgetmask shmat shmctl shmdt shmget shmop shutdown sigaction
+sigaltstack sigblock siggetmask sigmask signal sigpause sigpending
+sigprocmask sigreturn sigsetmask sigsuspend sigvec socket socketcall
+socketpair ssetmask statfs stime stty swapoff swapon syscalls sysctl
+sysfs sysinfo times ulimit umount uname ustat vfork vhangup wait3
+wait4 writev
+
+4) In the spec but not implemented:
 
 - buffers
 
index 477a6bd..da8b82b 100644 (file)
@@ -1,5 +1,5 @@
 (defpackage :sb-posix (:use #:sb-alien #:cl)
-  (:shadow close open ftruncate truncate time)
+  (:shadow close open ftruncate truncate time read write)
   (:export #:syscall-error #:syscall-errno
 
            ;; types and type conversion
index 7e10319..ac580c7 100644 (file)
                        (open-with-mode pathname flags mode)
                        (open-without-mode pathname flags))))))
     (def #-win32 "open" #+win32 "_open"))
+(define-call* "read" int minusp
+    (fd file-descriptor) (buf (* t)) (count int))
 (define-call "rename" int minusp (oldpath filename) (newpath filename))
 (define-call* "rmdir" int minusp (pathname filename))
 (define-call* "unlink" int minusp (pathname filename))
 (define-call #-netbsd "opendir" #+netbsd "_opendir"
     (* t) null-alien (pathname filename))
+(define-call* "write" int minusp
+    (fd file-descriptor) (buf (* t)) (count int))
 #+inode64
 (define-call ("readdir" :c-name "readdir$INODE64" :options :largefile)
   (* dirent)
index d87102f..d257086 100644 (file)
         kid-status))
   42)
 
+(deftest read.1
+    (progn
+      (with-open-file (ouf (merge-pathnames "read-test.txt" *test-directory*)
+                           :direction :output
+                           :if-exists :supersede
+                           :if-does-not-exist :create)
+        (write-string "foo" ouf))
+      (let ((fd (sb-posix:open (merge-pathnames "read-test.txt" *test-directory*) sb-posix:o-rdonly)))
+        (unwind-protect
+             (let ((buf (make-array 10 :element-type '(unsigned-byte 8))))
+               (values
+                (sb-posix:read fd (sb-sys:vector-sap buf) 10)
+                (code-char (aref buf 0))
+                (code-char (aref buf 1))
+                (code-char (aref buf 2))))
+          (sb-posix:close fd))))
+  3 #\f #\o #\o)
+
 (deftest opendir.1
   (let ((dir (sb-posix:opendir "/")))
     (unwind-protect (sb-alien:null-alien dir)
         (sb-posix:closedir dir)))
   t)
 
+
+(deftest write.1
+    (progn
+      (let ((fd (sb-posix:open (merge-pathnames "write-test.txt" *test-directory*)
+                               (logior sb-posix:o-creat sb-posix:o-wronly)
+                               (logior sb-posix:s-irusr sb-posix:s-iwusr)))
+            (retval nil))
+        (unwind-protect
+             (let ((buf (coerce "foo" 'simple-base-string)))
+               (setf retval (sb-posix:write fd (sb-sys:vector-sap buf) 3)))
+          (sb-posix:close fd))
+
+        (with-open-file (inf (merge-pathnames "write-test.txt" *test-directory*)
+                             :direction :input)
+          (values retval (read-line inf)))))
+  3 "foo")
+
 #-win32
 (deftest pwent.1
   ;; make sure that we found something
index e046cda..f6aa8f1 100644 (file)
@@ -20,4 +20,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.47.4"
+"1.0.47.5"