From f5f065ce75f1be381a1c7cd7eced7c0a8310adbd Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 8 May 2008 06:13:14 -0500 Subject: [PATCH] Unix 'open' now throws an exception. The low-level 'open' is now in unix.ffi. --- extra/unix/ffi/ffi.factor | 6 ++++++ extra/unix/unix.factor | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 extra/unix/ffi/ffi.factor diff --git a/extra/unix/ffi/ffi.factor b/extra/unix/ffi/ffi.factor new file mode 100644 index 0000000000..11a8405b1d --- /dev/null +++ b/extra/unix/ffi/ffi.factor @@ -0,0 +1,6 @@ + +USING: alien.syntax ; + +IN: unix.ffi + +FUNCTION: int open ( char* path, int flags, int prot ) ; \ No newline at end of file diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 9005cd2b2a..38af4b8695 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -2,7 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.syntax kernel libc structs -math namespaces system combinators vocabs.loader unix.types ; + math namespaces system combinators vocabs.loader unix.ffi unix.types + qualified ; + +QUALIFIED: unix.ffi IN: unix @@ -75,7 +78,17 @@ FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_ FUNCTION: int munmap ( void* addr, size_t len ) ; FUNCTION: uint ntohl ( uint n ) ; FUNCTION: ushort ntohs ( ushort n ) ; -FUNCTION: int open ( char* path, int flags, int prot ) ; +FUNCTION: char* strerror ( int errno ) ; + +TUPLE: open-error path flags prot message ; + +: open ( path flags prot -- int ) + [ ] [ unix.ffi:open ] 3bi + dup 0 >= + [ nip nip nip ] + [ drop err_no strerror open-error boa throw ] + if ; + FUNCTION: int pclose ( void* file ) ; FUNCTION: int pipe ( int* filedes ) ; FUNCTION: void* popen ( char* command, char* type ) ; @@ -96,7 +109,6 @@ FUNCTION: int setreuid ( uid_t ruid, uid_t euid ) ; FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_t optlen ) ; FUNCTION: int setuid ( uid_t uid ) ; FUNCTION: int socket ( int domain, int type, int protocol ) ; -FUNCTION: char* strerror ( int errno ) ; FUNCTION: int symlink ( char* path1, char* path2 ) ; FUNCTION: int system ( char* command ) ; FUNCTION: int unlink ( char* path ) ;