[Gd-chatter] r11162 - in trunk/fundev/sources: lib/unix-portability network network/unix-sockets system/file-system

hannes at gwydiondylan.org hannes at gwydiondylan.org
Sat Feb 3 00:29:50 CET 2007


Author: hannes
Date: Sat Feb  3 00:29:47 2007
New Revision: 11162

Added:
   trunk/fundev/sources/lib/unix-portability/linux.c   (contents, props changed)
Modified:
   trunk/fundev/sources/lib/unix-portability/freebsd-portability.dylan
   trunk/fundev/sources/lib/unix-portability/library.dylan
   trunk/fundev/sources/lib/unix-portability/linux-portability.dylan
   trunk/fundev/sources/lib/unix-portability/linux-portability.lid
   trunk/fundev/sources/lib/unix-portability/win32-portability.dylan
   trunk/fundev/sources/network/unix-network-library.dylan
   trunk/fundev/sources/network/unix-sockets/errno.dylan
   trunk/fundev/sources/system/file-system/unix-ffi.dylan
   trunk/fundev/sources/system/file-system/unix-file-accessor.dylan
   trunk/fundev/sources/system/file-system/unix-file-system.dylan
   trunk/fundev/sources/system/file-system/unix-interface.dylan
Log:
Job: fd
use errno on linux instead of deprecated __errno_location
unify access to C's errno via unix-portability


Modified: trunk/fundev/sources/lib/unix-portability/freebsd-portability.dylan
==============================================================================
--- trunk/fundev/sources/lib/unix-portability/freebsd-portability.dylan	(original)
+++ trunk/fundev/sources/lib/unix-portability/freebsd-portability.dylan	Sat Feb  3 00:29:47 2007
@@ -1,22 +1,22 @@
 module: unix-portability
 author: Hannes Mehnert <hannes at mehnert.org>
 
-define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>) => (position :: <integer>)
-raw-as-integer(
-  %call-c-function ("mylseek")
-    (fd :: <raw-c-unsigned-int>, position :: <raw-c-unsigned-long>, 
-     mode :: <raw-c-unsigned-int>) 
-   => (result :: <raw-c-signed-int>)
-    (integer-as-raw(fd), integer-as-raw(position), integer-as-raw(mode))
-  end)
+define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>)
+ => (position :: <integer>)
+  raw-as-integer
+    (%call-c-function ("mylseek")
+       (fd :: <raw-c-unsigned-int>, position :: <raw-c-unsigned-long>, 
+        mode :: <raw-c-unsigned-int>) 
+       => (result :: <raw-c-signed-int>)
+       (integer-as-raw(fd), integer-as-raw(position), integer-as-raw(mode))
+     end)
 end;
 
-define function unix-errno () => (res :: <raw-c-signed-int>)
- primitive-c-signed-int-at(
-  %call-c-function ("__error") () => (errnop :: <raw-pointer>) () end,
-   integer-as-raw(0), integer-as-raw(0))
+define function unix-errno () => (res :: <integer>)
+ raw-as-integer
+  (primitive-c-signed-int-at
+     (%call-c-function ("__error") () => (errnop :: <raw-pointer>) () end,
+     integer-as-raw(0), integer-as-raw(0)))
 end;
 
 define constant $proc-path = "file";
-
-define constant $errno-location = "__error";

Modified: trunk/fundev/sources/lib/unix-portability/library.dylan
==============================================================================
--- trunk/fundev/sources/lib/unix-portability/library.dylan	(original)
+++ trunk/fundev/sources/lib/unix-portability/library.dylan	Sat Feb  3 00:29:47 2007
@@ -11,5 +11,5 @@
   use dylan;
   use dylan-direct-c-ffi;
 
-  export unix-errno, $proc-path, $errno-location, unix-lseek;
+  export unix-errno, $proc-path, unix-lseek;
 end;
\ No newline at end of file

Modified: trunk/fundev/sources/lib/unix-portability/linux-portability.dylan
==============================================================================
--- trunk/fundev/sources/lib/unix-portability/linux-portability.dylan	(original)
+++ trunk/fundev/sources/lib/unix-portability/linux-portability.dylan	Sat Feb  3 00:29:47 2007
@@ -1,22 +1,21 @@
 module: unix-portability
 author: Hannes Mehnert <hannes at mehnert.org>
 
-define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>) => (position :: <integer>)
-raw-as-integer(
-  %call-c-function ("lseek")
-    (fd :: <raw-c-unsigned-int>, position :: <raw-c-unsigned-long>, 
-     mode :: <raw-c-unsigned-int>) 
-   => (result :: <raw-c-signed-int>)
-    (integer-as-raw(fd), integer-as-raw(position), integer-as-raw(mode))
-  end)
+define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>)
+ => (position :: <integer>)
+  raw-as-integer
+    (%call-c-function ("lseek")
+       (fd :: <raw-c-unsigned-int>, position :: <raw-c-unsigned-long>, 
+        mode :: <raw-c-unsigned-int>) 
+       => (result :: <raw-c-signed-int>)
+       (integer-as-raw(fd), integer-as-raw(position), integer-as-raw(mode))
+     end)
 end;
 
-define function unix-errno () => (res :: <raw-c-signed-int>)
- primitive-c-signed-int-at(
-  %call-c-function ("__errno_location") () => (errnop :: <raw-pointer>) () end,
-   integer-as-raw(0), integer-as-raw(0))
+
+
+define function unix-errno () => (res :: <integer>)
+ raw-as-integer(%call-c-function ("myerrno") () => (errnop :: <raw-c-signed-int>) () end)
 end;
 
 define constant $proc-path = "exe";
-
-define constant $errno-location = "__errno_location";
\ No newline at end of file

Modified: trunk/fundev/sources/lib/unix-portability/linux-portability.lid
==============================================================================
--- trunk/fundev/sources/lib/unix-portability/linux-portability.lid	(original)
+++ trunk/fundev/sources/lib/unix-portability/linux-portability.lid	Sat Feb  3 00:29:47 2007
@@ -1,5 +1,6 @@
 Library: unix-portability
 Author: Hannes Mehnert <hannes at mehnert.org>
 Synopsis: Hide unix specifica (__error, __errno_location)
+C-Source-Files: linux.c
 Files: library
        linux-portability
\ No newline at end of file

Added: trunk/fundev/sources/lib/unix-portability/linux.c
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/lib/unix-portability/linux.c	Sat Feb  3 00:29:47 2007
@@ -0,0 +1,6 @@
+#include <errno.h>
+
+int myerrno () {
+     return errno;
+}
+

Modified: trunk/fundev/sources/lib/unix-portability/win32-portability.dylan
==============================================================================
--- trunk/fundev/sources/lib/unix-portability/win32-portability.dylan	(original)
+++ trunk/fundev/sources/lib/unix-portability/win32-portability.dylan	Sat Feb  3 00:29:47 2007
@@ -1,12 +1,11 @@
 module: unix-portability
 author: Hannes Mehnert <hannes at mehnert.org>
 
-define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>) => (position :: <integer>)
+define function unix-lseek (fd :: <integer>, position :: <integer>, mode :: <integer>)
+ => (position :: <integer>)
 end;
 
 define function unix-errno () => (res)
 end;
 
 define constant $proc-path = "";
-
-define constant $errno-location = "";

Modified: trunk/fundev/sources/network/unix-network-library.dylan
==============================================================================
--- trunk/fundev/sources/network/unix-network-library.dylan	(original)
+++ trunk/fundev/sources/network/unix-network-library.dylan	Sat Feb  3 00:29:47 2007
@@ -165,7 +165,6 @@
   export
     gethostname;
   export
-    errno,
     $EPERM, $ENOENT, $ESRCH, $EINTR, $EIO, $ENXIO, $E2BIG, $ENOEXEC,
     $EBADF, $ECHILD, $EAGAIN, $EWOULDBLOCK, $ENOMEM, $EACCES, $EFAULT,
     $ENOTBLK, $EBUSY, $EEXIST, $EXDEV, $ENODEV, $ENOTDIR, $EISDIR,
@@ -255,6 +254,7 @@
   use format;
   use format-out;
   use byte-vector;
+  use unix-portability;
   use unix-sockets,
     rename: {socket => unix-socket,
              connect => unix-connect,
@@ -270,8 +270,7 @@
 	     getpeername => unix-getpeername,
 	     gethostname => unix-gethostname,
 	     <c-socket> => <unix-socket-descriptor>,
-	     close => unix-closesocket,
-             errno => unix-errno},
+	     close => unix-closesocket },
     exclude: {<socket>, // use <accessor-socket-descriptor>
 	      send,  //  use unix-send-buffer instead
 	      recv};  //  use unix-recv-buffer instead

Modified: trunk/fundev/sources/network/unix-sockets/errno.dylan
==============================================================================
--- trunk/fundev/sources/network/unix-sockets/errno.dylan	(original)
+++ trunk/fundev/sources/network/unix-sockets/errno.dylan	Sat Feb  3 00:29:47 2007
@@ -1,18 +1,8 @@
 module: unix-sockets
 
 /* These values come from the headers of an x86 Linux machine.
-   Other Linux platforms are expected to be the same, but not
-   guaranteed.  __errno_location is glibc-specific, but we have
-   no other chance than swallowing this toad here. */
-
-define inline-only C-function errno-location
-  result val :: <C-int*>;
-  c-name: $errno-location;
-end C-function;
-
-define function errno() => (error-number :: <integer>)
-  as(<integer>, C-int-at(errno-location()));
-end function errno;
+   Other UNIX platforms are expected to be the same, but not
+   guaranteed. */
 
 define constant $EPERM           =   1;
 define constant $ENOENT          =   2;

Modified: trunk/fundev/sources/system/file-system/unix-ffi.dylan
==============================================================================
--- trunk/fundev/sources/system/file-system/unix-ffi.dylan	(original)
+++ trunk/fundev/sources/system/file-system/unix-ffi.dylan	Sat Feb  3 00:29:47 2007
@@ -185,16 +185,12 @@
 
 /// Error handling
 
-define function unix-last-error () => (errno :: <integer>)
-  raw-as-integer(unix-errno())
-end function unix-last-error;
-
 define function unix-last-error-message () => (message :: <string>)
   let message :: <byte-string>
     = primitive-raw-as-string
        (%call-c-function ("strerror")
 	    (errno :: <raw-c-signed-int>) => (message :: <raw-byte-string>)
-	  (integer-as-raw(unix-last-error()))
+	  (integer-as-raw(unix-errno()))
 	end);
   // Make a copy to avoid it being overwritten ...
   copy-sequence(message)

Modified: trunk/fundev/sources/system/file-system/unix-file-accessor.dylan
==============================================================================
--- trunk/fundev/sources/system/file-system/unix-file-accessor.dylan	(original)
+++ trunk/fundev/sources/system/file-system/unix-file-accessor.dylan	Sat Feb  3 00:29:47 2007
@@ -110,7 +110,7 @@
 	      if (unix-delete-file(pathstring))
 		logior(mode-code, $o_creat);
 	      else
-		let errno = unix-errno-value();
+		let errno = unix-errno();
 		if (errno = $e_access)
 		  return(signal(make(<invalid-file-permissions-error>,
 				     locator: locator)));
@@ -134,7 +134,7 @@
 	end;
     let fd = unix-open(pathstring, mode-code, $file_create_permissions);
     if (fd < 0)
-      let errno = unix-errno-value();
+      let errno = unix-errno();
       if (errno = $e_access)
 	return(signal(make(<invalid-file-permissions-error>,
 			   locator: locator)));

Modified: trunk/fundev/sources/system/file-system/unix-file-system.dylan
==============================================================================
--- trunk/fundev/sources/system/file-system/unix-file-system.dylan	(original)
+++ trunk/fundev/sources/system/file-system/unix-file-system.dylan	Sat Feb  3 00:29:47 2007
@@ -108,7 +108,7 @@
 	     (primitive-string-as-raw(as(<byte-string>, file)),
 	      primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(st)))
 	   end))
-      if (unix-last-error() = $ENOENT & if-not-exists)
+      if (unix-errno() = $ENOENT & if-not-exists)
 	if-not-exists
       else
 	unix-file-error("determine the type of", "%s", file)
@@ -140,7 +140,7 @@
 			    integer-as-raw(8192))
 		       end);
     if (count = -1)
-      unless (unix-last-error() = $ENOENT | unix-last-error() = $EINVAL)
+      unless (unix-errno() = $ENOENT | unix-errno() = $EINVAL)
 	unix-file-error("readlink", "%s", link)
       end
     else
@@ -366,7 +366,7 @@
 	  => (failed? :: <raw-c-signed-int>)
 	   (primitive-string-as-raw(as(<byte-string>, file)), abstract-integer-as-raw(mode))
 	 end))
-    unless (unix-last-error() = $EACCESS)
+    unless (unix-errno() = $EACCESS)
       unix-file-error("determine access to", "%s", file)
     end;
     #f
@@ -508,7 +508,7 @@
 /*
     if (primitive-machine-word-equal?
 	     (primitive-unwrap-machine-word(dirent),
-	      integer-as-raw($NO_MORE_DIRENTRIES)) & (unix-last-error() ~= 0))
+	      integer-as-raw($NO_MORE_DIRENTRIES)) & (unix-errno() ~= 0))
       unix-file-error("continue listing of", "%s", directory)
     end;
 */
@@ -605,7 +605,7 @@
 	let _end = position(buffer, '\0', test: \=);
 	return(as(<directory-locator>, copy-sequence(buffer, end: _end)))
       else
-	errno := unix-last-error();
+	errno := unix-errno();
 	bufsiz := bufsiz * 2;
       end
     end;

Modified: trunk/fundev/sources/system/file-system/unix-interface.dylan
==============================================================================
--- trunk/fundev/sources/system/file-system/unix-interface.dylan	(original)
+++ trunk/fundev/sources/system/file-system/unix-interface.dylan	Sat Feb  3 00:29:47 2007
@@ -13,7 +13,7 @@
     =>
   { iterate loop()
       let result = ?body;
-      if(result < 0 & unix-errno-value() == $EINTR)
+      if(result < 0 & unix-errno() == $EINTR)
         loop()
       else
         result
@@ -103,10 +103,6 @@
   copy-sequence(message)
 end function get-unix-error;
 
-define function unix-errno-value () => (errno :: <integer>)
-  raw-as-integer(unix-errno())
-end function unix-errno-value;
-
 
 /// HIGHER LEVEL INTERFACE
 
@@ -180,6 +176,6 @@
 define function unix-error (syscall :: <string>, #key errno = #f) => ()
   let message :: <string> 
    = get-unix-error
-       (if (~errno) unix-errno-value() else errno end);
+       (if (~errno) unix-errno() else errno end);
   error("%s %s", syscall, message);
 end function unix-error;



More information about the chatter mailing list