]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/libc/libc.factor
libc: adding memmove
[factor.git] / basis / libc / libc.factor
index fdb8ca6487c4187b4e5aca37dcc06f783fe6387a..644f35954a846553fa9db57a509682ae9be521a8 100644 (file)
@@ -2,20 +2,20 @@
 ! Copyright (C) 2007, 2010 Slava Pestov
 ! Copyright (C) 2007, 2008 Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.destructors alien.syntax assocs
-combinators continuations destructors destructors.private kernel math
-namespaces prettyprint sequences sets summary system vocabs vocabs.parser ;
+USING: accessors alien alien.c-types alien.destructors
+alien.syntax destructors destructors.private kernel math
+namespaces sequences sets summary system vocabs ;
 IN: libc
 
-<< "libc." os unparse append require >>
+HOOK: strerror os ( errno -- str )
 
 LIBRARY: factor
 
 FUNCTION-ALIAS: errno
-    int err_no ( ) ;
+    int err_no ( )
 
 FUNCTION-ALIAS: set-errno
-    void set_err_no ( int err-no ) ;
+    void set_err_no ( int err-no )
 
 : clear-errno ( -- )
     0 set-errno ;
@@ -26,26 +26,30 @@ FUNCTION-ALIAS: set-errno
 LIBRARY: libc
 
 FUNCTION-ALIAS: (malloc)
-    void* malloc ( size_t size ) ;
+    void* malloc ( size_t size )
 
 FUNCTION-ALIAS: (calloc)
-    void* calloc ( size_t count,  size_t size ) ;
+    void* calloc ( size_t count,  size_t size )
 
 FUNCTION-ALIAS: (free)
-    void free ( void* alien ) ;
+    void free ( void* alien )
 
 FUNCTION-ALIAS: (realloc)
-    void* realloc ( void* alien, size_t size ) ;
+    void* realloc ( void* alien, size_t size )
 
-HOOK: strerror os ( errno -- str )
+FUNCTION-ALIAS: strerror_unsafe
+    char* strerror ( int errno )
 
-FUNCTION: int strerror_r ( int errno, char* buf, size_t buflen ) ;
+! Add a default strerror even though it's not threadsafe
+M: object strerror strerror_unsafe ;
 
 ERROR: libc-error errno message ;
 
-: (io-error) ( -- * ) errno dup strerror libc-error ;
+: (throw-errno) ( errno -- * ) dup strerror libc-error ;
+
+: throw-errno ( -- * ) errno (throw-errno) ;
 
-: io-error ( n -- ) 0 < [ (io-error) ] when ;
+: io-error ( n -- ) 0 < [ throw-errno ] when ;
 
 <PRIVATE
 
@@ -103,17 +107,21 @@ PRIVATE>
 : free ( alien -- )
     >c-ptr [ delete-malloc ] [ (free) ] bi ;
 
-FUNCTION: void memset ( void* buf, int char, size_t size ) ;
+FUNCTION: void memset ( void* buf, int char, size_t size )
 
-FUNCTION: void memcpy ( void* dst, void* src, ulong size ) ;
+FUNCTION: void memcpy ( void* dst, void* src, ulong size )
 
-FUNCTION: int memcmp ( void* a, void* b, ulong size ) ;
+FUNCTION: void memmove ( void* dst, void* src, ulong size )
+
+FUNCTION: int memcmp ( void* a, void* b, ulong size )
 
 : memory= ( a b size -- ? ) memcmp 0 = ; inline
 
-FUNCTION: size_t strlen ( c-string alien ) ;
+FUNCTION: size_t strlen ( c-string alien )
 
-FUNCTION: int system ( c-string command ) ;
+FUNCTION: int system ( c-string command )
 
 DESTRUCTOR: free
-DESTRUCTOR: (free)
+
+! For libc.linux, libc.windows, libc.macosx...
+<< "libc." os name>> append require >>