]> gitweb.factorcode.org Git - factor.git/commitdiff
libc: First stab at using strerror_r and (strerror_s on Windows) instead of thread...
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 4 Jul 2014 10:11:45 +0000 (03:11 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 4 Jul 2014 10:11:45 +0000 (03:11 -0700)
basis/libc/libc.factor
basis/libc/windows/windows.factor

index ee5f7abad7aad28e166b7fd38f9f9d2a1499140a..fdb8ca6487c4187b4e5aca37dcc06f783fe6387a 100644 (file)
@@ -25,14 +25,6 @@ FUNCTION-ALIAS: set-errno
 
 LIBRARY: libc
 
-FUNCTION: c-string strerror ( int errno ) ;
-
-ERROR: libc-error errno message ;
-
-: (io-error) ( -- * ) errno dup strerror libc-error ;
-
-: io-error ( n -- ) 0 < [ (io-error) ] when ;
-
 FUNCTION-ALIAS: (malloc)
     void* malloc ( size_t size ) ;
 
@@ -45,6 +37,16 @@ FUNCTION-ALIAS: (free)
 FUNCTION-ALIAS: (realloc)
     void* realloc ( void* alien, size_t size ) ;
 
+HOOK: strerror os ( errno -- str )
+
+FUNCTION: int strerror_r ( int errno, char* buf, size_t buflen ) ;
+
+ERROR: libc-error errno message ;
+
+: (io-error) ( -- * ) errno dup strerror libc-error ;
+
+: io-error ( n -- ) 0 < [ (io-error) ] when ;
+
 <PRIVATE
 
 ! We stick malloc-ptr instances in the global disposables set
index 0f4be2213c1432cd252b987c2a33add9ec08bec5..afaecf9b38a8565b4dd426ba326746c93b4e8134 100644 (file)
@@ -1,4 +1,4 @@
-USING: alien.syntax ;
+USING: alien.strings destructors kernel libc system ;
 IN: libc
 
 LIBRARY: libc
@@ -102,3 +102,14 @@ CONSTANT: SIGBREAK        21
 CONSTANT: SIGABRT         22
 
 CONSTANT: SIGABRT_COMPAT  6
+
+LIBRARY: libc
+
+FUNCTION: int strerror_s ( char *buffer, size_t numberOfElements, int errnum ) ;
+
+M: windows strerror ( errno -- str )
+    [
+        [ 1024 [ malloc &free ] keep ] dip
+        [ strerror_s drop ] 3keep 2drop
+        alien>native-string
+    ] with-destructors ;