 : preserve-errno ( quot -- )
     errno [ call ] dip set-errno ; inline
 
-: (malloc) ( size -- alien )
-    void* "libc" "malloc" { ulong } alien-invoke ;
+LIBRARY: libc
 
-: (calloc) ( count size -- alien )
-    void* "libc" "calloc" { ulong ulong } alien-invoke ;
+FUNCTION-ALIAS: (malloc)
+    void* malloc ( ulong size ) ;
 
-: (free) ( alien -- )
-    void "libc" "free" { void* } alien-invoke ;
+FUNCTION-ALIAS: (calloc)
+    void* calloc ( ulong count,  ulong size ) ;
 
-: (realloc) ( alien size -- newalien )
-    void* "libc" "realloc" { void* ulong } alien-invoke ;
+FUNCTION-ALIAS: (free)
+    void free ( void* alien ) ;
+
+FUNCTION-ALIAS: (realloc)
+    void* realloc ( void* alien, ulong size ) ;
 
 <PRIVATE
 

! Copyright (C) 2007, 2010 Slava Pestov
! Copyright (C) 2007, 2008 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types assocs continuations alien.destructors kernel
namespaces accessors sets summary destructors destructors.private ;
IN: libc

: errno ( -- int )
    int "factor" "err_no" { } alien-invoke ;

: set-errno ( int -- )
    void "factor" "set_err_no" { int } alien-invoke ;

: clear-errno ( -- )
    0 set-errno ;

: free ( alien -- )
    >c-ptr [ delete-malloc ] [ (free) ] bi ;

FUNCTION: void memcpy ( void* dst, void* src, ulong size ) ;

FUNCTION: int memcmp ( void* a, void* b, ulong size ) ;

: memory= ( a b size -- ? )
    memcmp 0 = ;

FUNCTION: size_t strlen ( c-string alien ) ;

DESTRUCTOR: free
DESTRUCTOR: (free)
