diff --git a/basis/environment/unix/unix.factor b/basis/environment/unix/unix.factor index 3fc8c2f79b..ec41e919d8 100644 --- a/basis/environment/unix/unix.factor +++ b/basis/environment/unix/unix.factor @@ -3,7 +3,7 @@ USING: alien alien.c-types alien.data alien.strings alien.syntax kernel layouts sequences system unix environment io.encodings.utf8 unix.utilities vocabs.loader -combinators alien.accessors ; +combinators alien.accessors unix.ffi ; IN: environment.unix HOOK: environ os ( -- void* ) diff --git a/basis/io/backend/unix/unix.factor b/basis/io/backend/unix/unix.factor index 2ab5bdca05..6412132725 100644 --- a/basis/io/backend/unix/unix.factor +++ b/basis/io/backend/unix/unix.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.syntax generic assocs kernel kernel.private math io.ports sequences strings sbufs threads -unix vectors io.buffers io.backend io.encodings math.parser +unix unix.ffi vectors io.buffers io.backend io.encodings math.parser continuations system libc namespaces make io.timeouts io.encodings.utf8 destructors destructors.private accessors summary combinators locals unix.time unix.types fry diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor index b1f6596759..a62a431de8 100644 --- a/basis/io/directories/unix/unix.factor +++ b/basis/io/directories/unix/unix.factor @@ -4,7 +4,7 @@ USING: accessors alien.c-types alien.strings combinators continuations destructors fry io io.backend io.backend.unix io.directories io.encodings.binary io.encodings.utf8 io.files io.pathnames io.files.types kernel math.bitwise sequences system -unix unix.stat vocabs.loader classes.struct ; +unix unix.stat vocabs.loader classes.struct unix.ffi ; IN: io.directories.unix : touch-mode ( -- n ) diff --git a/basis/io/files/info/info.factor b/basis/io/files/info/info.factor index 60a9308f38..500fd62cd3 100644 --- a/basis/io/files/info/info.factor +++ b/basis/io/files/info/info.factor @@ -26,7 +26,7 @@ available-space free-space used-space total-space ; HOOK: file-system-info os ( path -- file-system-info ) { - { [ os unix? ] [ "io.files.info.unix." os name>> append ] } + { [ os unix? ] [ "io.files.info" ] } { [ os windows? ] [ "io.files.info.windows" ] } } cond require diff --git a/basis/io/files/info/unix/unix.factor b/basis/io/files/info/unix/unix.factor index 180f194c89..ff604759c1 100644 --- a/basis/io/files/info/unix/unix.factor +++ b/basis/io/files/info/unix/unix.factor @@ -1,13 +1,13 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel system math math.bitwise strings arrays -sequences combinators combinators.short-circuit alien.c-types -vocabs.loader calendar calendar.unix io.files.info -io.files.types io.backend io.directories unix unix.stat -unix.time unix.users unix.groups classes.struct -specialized-arrays literals ; -SPECIALIZED-ARRAY: timeval +USING: accessors alien.c-types arrays calendar calendar.unix +classes.struct combinators combinators.short-circuit io.backend +io.directories io.files.info io.files.types kernel literals +math math.bitwise sequences specialized-arrays strings system +unix unix.ffi unix.groups unix.stat unix.time unix.users +vocabs.loader ; IN: io.files.info.unix +SPECIALIZED-ARRAY: timeval TUPLE: unix-file-system-info < file-system-info block-size preferred-block-size @@ -286,3 +286,5 @@ PRIVATE> { +regular-file+ [ file-type>executable ] } [ drop file-type>executable ] } case ; + +"io.files.info.unix." os name>> append require diff --git a/basis/io/files/links/unix/unix.factor b/basis/io/files/links/unix/unix.factor index ced4c11c59..f97478c332 100644 --- a/basis/io/files/links/unix/unix.factor +++ b/basis/io/files/links/unix/unix.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: io.backend io.files.links system unix io.pathnames kernel -io.files sequences ; +USING: io.backend io.files io.files.links io.pathnames kernel +sequences system unix unix.ffi ; IN: io.files.links.unix M: unix make-link ( path1 path2 -- ) diff --git a/basis/io/files/unix/unix.factor b/basis/io/files/unix/unix.factor index 783e40a70c..7293cf67fa 100644 --- a/basis/io/files/unix/unix.factor +++ b/basis/io/files/unix/unix.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: unix byte-arrays kernel io.backend.unix math.bitwise io.ports io.files io.files.private io.pathnames environment -destructors system ; +destructors system unix.ffi ; IN: io.files.unix M: unix cwd ( -- path ) diff --git a/basis/io/launcher/unix/unix.factor b/basis/io/launcher/unix/unix.factor index a9e3324986..28c805a528 100644 --- a/basis/io/launcher/unix/unix.factor +++ b/basis/io/launcher/unix/unix.factor @@ -5,7 +5,7 @@ continuations environment io io.backend io.backend.unix io.files io.files.private io.files.unix io.launcher io.launcher.unix.parser io.pathnames io.ports kernel math namespaces sequences strings system threads unix -unix.process ; +unix.process unix.ffi ; IN: io.launcher.unix : get-arguments ( process -- seq ) diff --git a/basis/io/pipes/unix/unix.factor b/basis/io/pipes/unix/unix.factor index 8493f14d26..7dbeb0a589 100644 --- a/basis/io/pipes/unix/unix.factor +++ b/basis/io/pipes/unix/unix.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types system kernel unix math sequences -io.backend.unix io.ports specialized-arrays accessors ; +io.backend.unix io.ports specialized-arrays accessors unix.ffi ; QUALIFIED: io.pipes SPECIALIZED-ARRAY: int IN: io.pipes.unix diff --git a/basis/io/sockets/secure/unix/unix.factor b/basis/io/sockets/secure/unix/unix.factor index b04d282530..8fe9facc0c 100644 --- a/basis/io/sockets/secure/unix/unix.factor +++ b/basis/io/sockets/secure/unix/unix.factor @@ -6,7 +6,8 @@ alien.strings libc continuations destructors openssl openssl.libcrypto openssl.libssl io io.files io.ports io.backend.unix io.sockets.unix io.encodings.ascii io.buffers io.sockets io.sockets.private io.sockets.secure -io.sockets.secure.openssl io.timeouts system summary fry ; +io.sockets.secure.openssl io.timeouts system summary fry +unix.ffi ; FROM: io.ports => shutdown ; IN: io.sockets.secure.unix diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index e45224fcc2..af21dac9b7 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -11,7 +11,7 @@ IN: io.sockets << { { [ os windows? ] [ "windows.winsock" ] } - { [ os unix? ] [ "unix" ] } + { [ os unix? ] [ "unix.ffi" ] } } cond use-vocab >> ! Addressing diff --git a/basis/io/sockets/unix/unix.factor b/basis/io/sockets/unix/unix.factor index 4f25435985..fcf84f7925 100644 --- a/basis/io/sockets/unix/unix.factor +++ b/basis/io/sockets/unix/unix.factor @@ -5,7 +5,7 @@ threads sequences byte-arrays io.binary io.backend.unix io.streams.duplex io.backend io.pathnames io.sockets.private io.files.private io.encodings.utf8 math.parser continuations libc combinators system accessors destructors unix locals init -classes.struct alien.data ; +classes.struct alien.data unix.ffi ; EXCLUDE: namespaces => bind ; EXCLUDE: io => read write ; diff --git a/basis/unix/debugger/debugger.factor b/basis/unix/debugger/debugger.factor index 4e276373e1..7a085731d1 100644 --- a/basis/unix/debugger/debugger.factor +++ b/basis/unix/debugger/debugger.factor @@ -1,7 +1,6 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: debugger prettyprint accessors unix kernel ; -FROM: io => write print nl ; +USING: accessors debugger io kernel prettyprint unix ; IN: unix.debugger M: unix-error error. diff --git a/basis/unix/ffi/authors.txt b/basis/unix/ffi/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/unix/ffi/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/unix/bsd/authors.txt b/basis/unix/ffi/bsd/authors.txt similarity index 100% rename from basis/unix/bsd/authors.txt rename to basis/unix/ffi/bsd/authors.txt diff --git a/basis/unix/bsd/bsd.factor b/basis/unix/ffi/bsd/bsd.factor similarity index 89% rename from basis/unix/bsd/bsd.factor rename to basis/unix/ffi/bsd/bsd.factor index 0825e42930..bda99422fc 100644 --- a/basis/unix/bsd/bsd.factor +++ b/basis/unix/ffi/bsd/bsd.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.syntax classes.struct combinators system unix.types vocabs.loader ; -IN: unix +IN: unix.ffi CONSTANT: MAXPATHLEN 1024 @@ -85,8 +85,8 @@ CONSTANT: SEEK_CUR 1 CONSTANT: SEEK_END 2 os { - { macosx [ "unix.bsd.macosx" require ] } - { freebsd [ "unix.bsd.freebsd" require ] } - { openbsd [ "unix.bsd.openbsd" require ] } - { netbsd [ "unix.bsd.netbsd" require ] } + { macosx [ "unix.ffi.bsd.macosx" require ] } + { freebsd [ "unix.ffi.bsd.freebsd" require ] } + { openbsd [ "unix.ffi.bsd.openbsd" require ] } + { netbsd [ "unix.ffi.bsd.netbsd" require ] } } case diff --git a/basis/unix/bsd/freebsd/freebsd.factor b/basis/unix/ffi/bsd/freebsd/freebsd.factor similarity index 99% rename from basis/unix/bsd/freebsd/freebsd.factor rename to basis/unix/ffi/bsd/freebsd/freebsd.factor index e6a2070520..992d1c3ad0 100644 --- a/basis/unix/bsd/freebsd/freebsd.factor +++ b/basis/unix/ffi/bsd/freebsd/freebsd.factor @@ -1,5 +1,5 @@ USING: alien.c-types alien.syntax classes.struct unix.types ; -IN: unix +IN: unix.ffi CONSTANT: FD_SETSIZE 1024 diff --git a/basis/unix/bsd/freebsd/tags.txt b/basis/unix/ffi/bsd/freebsd/tags.txt similarity index 100% rename from basis/unix/bsd/freebsd/tags.txt rename to basis/unix/ffi/bsd/freebsd/tags.txt diff --git a/basis/unix/bsd/macosx/macosx.factor b/basis/unix/ffi/bsd/macosx/macosx.factor similarity index 95% rename from basis/unix/bsd/macosx/macosx.factor rename to basis/unix/ffi/bsd/macosx/macosx.factor index c263be7056..a2e75b6ca6 100644 --- a/basis/unix/bsd/macosx/macosx.factor +++ b/basis/unix/ffi/bsd/macosx/macosx.factor @@ -1,6 +1,7 @@ -USING: alien.c-types alien.syntax unix.time unix.types -unix.types.macosx classes.struct ; -IN: unix +USING: alien alien.c-types alien.libraries alien.syntax +classes.struct combinators kernel system unix unix.time +unix.types vocabs vocabs.loader ; +IN: unix.ffi CONSTANT: FD_SETSIZE 1024 diff --git a/basis/unix/bsd/macosx/tags.txt b/basis/unix/ffi/bsd/macosx/tags.txt similarity index 100% rename from basis/unix/bsd/macosx/tags.txt rename to basis/unix/ffi/bsd/macosx/tags.txt diff --git a/basis/unix/bsd/netbsd/netbsd.factor b/basis/unix/ffi/bsd/netbsd/netbsd.factor similarity index 98% rename from basis/unix/bsd/netbsd/netbsd.factor rename to basis/unix/ffi/bsd/netbsd/netbsd.factor index 6bef08abe3..0aee585b48 100644 --- a/basis/unix/bsd/netbsd/netbsd.factor +++ b/basis/unix/ffi/bsd/netbsd/netbsd.factor @@ -1,6 +1,6 @@ USING: alien.syntax alien.c-types math vocabs.loader classes.struct unix.types ; -IN: unix +IN: unix.ffi CONSTANT: FD_SETSIZE 256 @@ -138,4 +138,4 @@ CONSTANT: _SS_MAXSIZE 128 : _SS_PAD2SIZE ( -- n ) _SS_MAXSIZE 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE - ; inline -"unix.bsd.netbsd.structs" require +"unix.ffi.bsd.netbsd.structs" require diff --git a/basis/unix/bsd/netbsd/structs/structs.factor b/basis/unix/ffi/bsd/netbsd/structs/structs.factor similarity index 100% rename from basis/unix/bsd/netbsd/structs/structs.factor rename to basis/unix/ffi/bsd/netbsd/structs/structs.factor diff --git a/basis/unix/bsd/netbsd/structs/tags.txt b/basis/unix/ffi/bsd/netbsd/structs/tags.txt similarity index 100% rename from basis/unix/bsd/netbsd/structs/tags.txt rename to basis/unix/ffi/bsd/netbsd/structs/tags.txt diff --git a/basis/unix/bsd/netbsd/tags.txt b/basis/unix/ffi/bsd/netbsd/tags.txt similarity index 100% rename from basis/unix/bsd/netbsd/tags.txt rename to basis/unix/ffi/bsd/netbsd/tags.txt diff --git a/basis/unix/bsd/openbsd/openbsd.factor b/basis/unix/ffi/bsd/openbsd/openbsd.factor similarity index 99% rename from basis/unix/bsd/openbsd/openbsd.factor rename to basis/unix/ffi/bsd/openbsd/openbsd.factor index f48b7c1ac4..076dbdfd24 100644 --- a/basis/unix/bsd/openbsd/openbsd.factor +++ b/basis/unix/ffi/bsd/openbsd/openbsd.factor @@ -1,5 +1,5 @@ USING: alien.c-types alien.syntax classes.struct unix.types ; -IN: unix +IN: unix.ffi CONSTANT: FD_SETSIZE 1024 diff --git a/basis/unix/bsd/openbsd/tags.txt b/basis/unix/ffi/bsd/openbsd/tags.txt similarity index 100% rename from basis/unix/bsd/openbsd/tags.txt rename to basis/unix/ffi/bsd/openbsd/tags.txt diff --git a/basis/unix/bsd/summary.txt b/basis/unix/ffi/bsd/summary.txt similarity index 100% rename from basis/unix/bsd/summary.txt rename to basis/unix/ffi/bsd/summary.txt diff --git a/basis/unix/bsd/tags.txt b/basis/unix/ffi/bsd/tags.txt similarity index 100% rename from basis/unix/bsd/tags.txt rename to basis/unix/ffi/bsd/tags.txt diff --git a/basis/unix/ffi/ffi.factor b/basis/unix/ffi/ffi.factor new file mode 100644 index 0000000000..3882f6fc80 --- /dev/null +++ b/basis/unix/ffi/ffi.factor @@ -0,0 +1,158 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien alien.c-types alien.libraries alien.syntax +classes.struct combinators kernel system unix.time unix.types +vocabs vocabs.loader ; +IN: unix.ffi + +<< + +{ + { [ os linux? ] [ "unix.ffi.linux" require ] } + { [ os bsd? ] [ "unix.ffi.bsd" require ] } + { [ os solaris? ] [ "unix.ffi.solaris" require ] } +} cond + +>> + +CONSTANT: PROT_NONE 0 +CONSTANT: PROT_READ 1 +CONSTANT: PROT_WRITE 2 +CONSTANT: PROT_EXEC 4 + +CONSTANT: MAP_FILE 0 +CONSTANT: MAP_SHARED 1 +CONSTANT: MAP_PRIVATE 2 + +CONSTANT: SEEK_SET 0 +CONSTANT: SEEK_CUR 1 +CONSTANT: SEEK_END 2 + +: MAP_FAILED ( -- alien ) -1 ; inline + +CONSTANT: NGROUPS_MAX 16 + +CONSTANT: DT_UNKNOWN 0 +CONSTANT: DT_FIFO 1 +CONSTANT: DT_CHR 2 +CONSTANT: DT_DIR 4 +CONSTANT: DT_BLK 6 +CONSTANT: DT_REG 8 +CONSTANT: DT_LNK 10 +CONSTANT: DT_SOCK 12 +CONSTANT: DT_WHT 14 + +LIBRARY: libc + +FUNCTION: char* strerror ( int errno ) ; + +STRUCT: group + { gr_name char* } + { gr_passwd char* } + { gr_gid int } + { gr_mem char** } ; + +FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen ) ; +FUNCTION: int bind ( int s, void* name, socklen_t namelen ) ; +FUNCTION: int chdir ( char* path ) ; +FUNCTION: int chmod ( char* path, mode_t mode ) ; +FUNCTION: int fchmod ( int fd, mode_t mode ) ; +FUNCTION: int chown ( char* path, uid_t owner, gid_t group ) ; +FUNCTION: int chroot ( char* path ) ; +FUNCTION: int close ( int fd ) ; +FUNCTION: int closedir ( DIR* dirp ) ; +FUNCTION: int connect ( int s, void* name, socklen_t namelen ) ; +FUNCTION: int dup2 ( int oldd, int newd ) ; +FUNCTION: void endpwent ( ) ; +FUNCTION: int fchdir ( int fd ) ; +FUNCTION: int fchown ( int fd, uid_t owner, gid_t group ) ; +FUNCTION: int fcntl ( int fd, int cmd, int arg ) ; +FUNCTION: int flock ( int fd, int operation ) ; +FUNCTION: void freeaddrinfo ( addrinfo* ai ) ; +FUNCTION: int futimes ( int id, timeval[2] times ) ; +FUNCTION: char* gai_strerror ( int ecode ) ; +FUNCTION: int getaddrinfo ( char* hostname, char* servname, addrinfo* hints, addrinfo** res ) ; +FUNCTION: char* getcwd ( char* buf, size_t size ) ; +FUNCTION: pid_t getpid ; +FUNCTION: int getdtablesize ; +FUNCTION: gid_t getegid ; +FUNCTION: uid_t geteuid ; +FUNCTION: gid_t getgid ; +FUNCTION: char* getenv ( char* name ) ; + +FUNCTION: int getgrgid_r ( gid_t gid, group* grp, char* buffer, size_t bufsize, group** result ) ; +FUNCTION: int getgrnam_r ( char* name, group* grp, char* buffer, size_t bufsize, group** result ) ; +FUNCTION: passwd* getpwent ( ) ; +FUNCTION: passwd* getpwuid ( uid_t uid ) ; +FUNCTION: passwd* getpwnam ( char* login ) ; +FUNCTION: int getpwnam_r ( char* login, passwd* pwd, char* buffer, size_t bufsize, passwd** result ) ; +FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset ) ; +FUNCTION: int getgrouplist ( char* name, int basegid, int* groups, int* ngroups ) ; +FUNCTION: int getrlimit ( int resource, rlimit* rlp ) ; +FUNCTION: int setrlimit ( int resource, rlimit* rlp ) ; +FUNCTION: int getpriority ( int which, id_t who ) ; +FUNCTION: int setpriority ( int which, id_t who, int prio ) ; +FUNCTION: int getrusage ( int who, rusage* r_usage ) ; +FUNCTION: group* getgrent ; +FUNCTION: int gethostname ( char* name, int len ) ; +FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len ) ; +FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len ) ; +FUNCTION: uid_t getuid ; +FUNCTION: uint htonl ( uint n ) ; +FUNCTION: ushort htons ( ushort n ) ; +! FUNCTION: int issetugid ; +FUNCTION: int ioctl ( int fd, ulong request, char* argp ) ; +FUNCTION: int lchown ( char* path, uid_t owner, gid_t group ) ; +FUNCTION: int listen ( int s, int backlog ) ; +FUNCTION: off_t lseek ( int fildes, off_t offset, int whence ) ; +FUNCTION: int mkdir ( char* path, mode_t mode ) ; +FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset ) ; +FUNCTION: int munmap ( void* addr, size_t len ) ; +FUNCTION: uint ntohl ( uint n ) ; +FUNCTION: ushort ntohs ( ushort n ) ; +FUNCTION: int shutdown ( int fd, int how ) ; +FUNCTION: int open ( char* path, int flags, int prot ) ; +FUNCTION: DIR* opendir ( char* path ) ; + +STRUCT: utimbuf + { actime time_t } + { modtime time_t } ; + +FUNCTION: int utime ( char* path, utimbuf* buf ) ; + +FUNCTION: int pclose ( void* file ) ; +FUNCTION: int pipe ( int* filedes ) ; +FUNCTION: void* popen ( char* command, char* type ) ; +FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ; + +FUNCTION: dirent* readdir ( DIR* dirp ) ; +FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result ) ; +FUNCTION: ssize_t readlink ( char* path, char* buf, size_t bufsize ) ; + +CONSTANT: PATH_MAX 1024 + +FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags ) ; +FUNCTION: ssize_t recvfrom ( int s, void* buf, size_t nbytes, int flags, sockaddr-in* from, socklen_t* fromlen ) ; +FUNCTION: int rename ( char* from, char* to ) ; +FUNCTION: int rmdir ( char* path ) ; +FUNCTION: int select ( int nfds, void* readfds, void* writefds, void* exceptfds, timeval* timeout ) ; +FUNCTION: ssize_t sendto ( int s, void* buf, size_t len, int flags, sockaddr-in* to, socklen_t tolen ) ; +FUNCTION: int setenv ( char* name, char* value, int overwrite ) ; +FUNCTION: int unsetenv ( char* name ) ; +FUNCTION: int setegid ( gid_t egid ) ; +FUNCTION: int seteuid ( uid_t euid ) ; +FUNCTION: int setgid ( gid_t gid ) ; +FUNCTION: int setgroups ( int ngroups, gid_t* gidset ) ; +FUNCTION: int setregid ( gid_t rgid, gid_t egid ) ; +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: int symlink ( char* path1, char* path2 ) ; +FUNCTION: int link ( char* path1, char* path2 ) ; +FUNCTION: int system ( char* command ) ; +FUNCTION: int unlink ( char* path ) ; +FUNCTION: int utimes ( char* path, timeval[2] times ) ; +FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ; + +"librt" "librt.so" "cdecl" add-library diff --git a/basis/unix/ffi/linux/authors.txt b/basis/unix/ffi/linux/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/unix/ffi/linux/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/unix/ffi/linux/linux.factor b/basis/unix/ffi/linux/linux.factor new file mode 100644 index 0000000000..260796b5e4 --- /dev/null +++ b/basis/unix/ffi/linux/linux.factor @@ -0,0 +1,236 @@ +! Copyright (C) 2010 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types alien.syntax classes.struct unix.types ; +IN: unix.ffi + +CONSTANT: MAXPATHLEN 1024 + +CONSTANT: O_RDONLY HEX: 0000 +CONSTANT: O_WRONLY HEX: 0001 +CONSTANT: O_RDWR HEX: 0002 +CONSTANT: O_CREAT HEX: 0040 +CONSTANT: O_EXCL HEX: 0080 +CONSTANT: O_NOCTTY HEX: 0100 +CONSTANT: O_TRUNC HEX: 0200 +CONSTANT: O_APPEND HEX: 0400 +CONSTANT: O_NONBLOCK HEX: 0800 + +ALIAS: O_NDELAY O_NONBLOCK + +CONSTANT: SOL_SOCKET 1 + +CONSTANT: FD_SETSIZE 1024 + +CONSTANT: SO_REUSEADDR 2 +CONSTANT: SO_OOBINLINE 10 +CONSTANT: SO_SNDTIMEO HEX: 15 +CONSTANT: SO_RCVTIMEO HEX: 14 + +CONSTANT: F_SETFD 2 +CONSTANT: FD_CLOEXEC 1 + +CONSTANT: F_SETFL 4 + +STRUCT: addrinfo + { flags int } + { family int } + { socktype int } + { protocol int } + { addrlen socklen_t } + { addr void* } + { canonname char* } + { next addrinfo* } ; + +STRUCT: sockaddr-in + { family ushort } + { port ushort } + { addr in_addr_t } + { unused longlong } ; + +STRUCT: sockaddr-in6 + { family ushort } + { port ushort } + { flowinfo uint } + { addr uchar[16] } + { scopeid uint } ; + +CONSTANT: max-un-path 108 + +STRUCT: sockaddr-un + { family ushort } + { path { char max-un-path } } ; + +CONSTANT: SOCK_STREAM 1 +CONSTANT: SOCK_DGRAM 2 + +CONSTANT: AF_UNSPEC 0 +CONSTANT: AF_UNIX 1 +CONSTANT: AF_INET 2 +CONSTANT: AF_INET6 10 + +ALIAS: PF_UNSPEC AF_UNSPEC +ALIAS: PF_UNIX AF_UNIX +ALIAS: PF_INET AF_INET +ALIAS: PF_INET6 AF_INET6 + +CONSTANT: IPPROTO_TCP 6 +CONSTANT: IPPROTO_UDP 17 + +CONSTANT: AI_PASSIVE 1 + +CONSTANT: SEEK_SET 0 +CONSTANT: SEEK_CUR 1 +CONSTANT: SEEK_END 2 + +STRUCT: passwd + { pw_name char* } + { pw_passwd char* } + { pw_uid uid_t } + { pw_gid gid_t } + { pw_gecos char* } + { pw_dir char* } + { pw_shell char* } ; + +! dirent64 +STRUCT: dirent + { d_ino ulonglong } + { d_off longlong } + { d_reclen ushort } + { d_type uchar } + { d_name char[256] } ; + +FUNCTION: int open64 ( char* path, int flags, int prot ) ; +FUNCTION: dirent* readdir64 ( DIR* dirp ) ; +FUNCTION: int readdir64_r ( void* dirp, dirent* entry, dirent** result ) ; + +CONSTANT: EPERM 1 +CONSTANT: ENOENT 2 +CONSTANT: ESRCH 3 +CONSTANT: EINTR 4 +CONSTANT: EIO 5 +CONSTANT: ENXIO 6 +CONSTANT: E2BIG 7 +CONSTANT: ENOEXEC 8 +CONSTANT: EBADF 9 +CONSTANT: ECHILD 10 +CONSTANT: EAGAIN 11 +CONSTANT: ENOMEM 12 +CONSTANT: EACCES 13 +CONSTANT: EFAULT 14 +CONSTANT: ENOTBLK 15 +CONSTANT: EBUSY 16 +CONSTANT: EEXIST 17 +CONSTANT: EXDEV 18 +CONSTANT: ENODEV 19 +CONSTANT: ENOTDIR 20 +CONSTANT: EISDIR 21 +CONSTANT: EINVAL 22 +CONSTANT: ENFILE 23 +CONSTANT: EMFILE 24 +CONSTANT: ENOTTY 25 +CONSTANT: ETXTBSY 26 +CONSTANT: EFBIG 27 +CONSTANT: ENOSPC 28 +CONSTANT: ESPIPE 29 +CONSTANT: EROFS 30 +CONSTANT: EMLINK 31 +CONSTANT: EPIPE 32 +CONSTANT: EDOM 33 +CONSTANT: ERANGE 34 +CONSTANT: EDEADLK 35 +CONSTANT: ENAMETOOLONG 36 +CONSTANT: ENOLCK 37 +CONSTANT: ENOSYS 38 +CONSTANT: ENOTEMPTY 39 +CONSTANT: ELOOP 40 +ALIAS: EWOULDBLOCK EAGAIN +CONSTANT: ENOMSG 42 +CONSTANT: EIDRM 43 +CONSTANT: ECHRNG 44 +CONSTANT: EL2NSYNC 45 +CONSTANT: EL3HLT 46 +CONSTANT: EL3RST 47 +CONSTANT: ELNRNG 48 +CONSTANT: EUNATCH 49 +CONSTANT: ENOCSI 50 +CONSTANT: EL2HLT 51 +CONSTANT: EBADE 52 +CONSTANT: EBADR 53 +CONSTANT: EXFULL 54 +CONSTANT: ENOANO 55 +CONSTANT: EBADRQC 56 +CONSTANT: EBADSLT 57 +ALIAS: EDEADLOCK EDEADLK +CONSTANT: EBFONT 59 +CONSTANT: ENOSTR 60 +CONSTANT: ENODATA 61 +CONSTANT: ETIME 62 +CONSTANT: ENOSR 63 +CONSTANT: ENONET 64 +CONSTANT: ENOPKG 65 +CONSTANT: EREMOTE 66 +CONSTANT: ENOLINK 67 +CONSTANT: EADV 68 +CONSTANT: ESRMNT 69 +CONSTANT: ECOMM 70 +CONSTANT: EPROTO 71 +CONSTANT: EMULTIHOP 72 +CONSTANT: EDOTDOT 73 +CONSTANT: EBADMSG 74 +CONSTANT: EOVERFLOW 75 +CONSTANT: ENOTUNIQ 76 +CONSTANT: EBADFD 77 +CONSTANT: EREMCHG 78 +CONSTANT: ELIBACC 79 +CONSTANT: ELIBBAD 80 +CONSTANT: ELIBSCN 81 +CONSTANT: ELIBMAX 82 +CONSTANT: ELIBEXEC 83 +CONSTANT: EILSEQ 84 +CONSTANT: ERESTART 85 +CONSTANT: ESTRPIPE 86 +CONSTANT: EUSERS 87 +CONSTANT: ENOTSOCK 88 +CONSTANT: EDESTADDRREQ 89 +CONSTANT: EMSGSIZE 90 +CONSTANT: EPROTOTYPE 91 +CONSTANT: ENOPROTOOPT 92 +CONSTANT: EPROTONOSUPPORT 93 +CONSTANT: ESOCKTNOSUPPORT 94 +CONSTANT: EOPNOTSUPP 95 +CONSTANT: EPFNOSUPPORT 96 +CONSTANT: EAFNOSUPPORT 97 +CONSTANT: EADDRINUSE 98 +CONSTANT: EADDRNOTAVAIL 99 +CONSTANT: ENETDOWN 100 +CONSTANT: ENETUNREACH 101 +CONSTANT: ENETRESET 102 +CONSTANT: ECONNABORTED 103 +CONSTANT: ECONNRESET 104 +CONSTANT: ENOBUFS 105 +CONSTANT: EISCONN 106 +CONSTANT: ENOTCONN 107 +CONSTANT: ESHUTDOWN 108 +CONSTANT: ETOOMANYREFS 109 +CONSTANT: ETIMEDOUT 110 +CONSTANT: ECONNREFUSED 111 +CONSTANT: EHOSTDOWN 112 +CONSTANT: EHOSTUNREACH 113 +CONSTANT: EALREADY 114 +CONSTANT: EINPROGRESS 115 +CONSTANT: ESTALE 116 +CONSTANT: EUCLEAN 117 +CONSTANT: ENOTNAM 118 +CONSTANT: ENAVAIL 119 +CONSTANT: EISNAM 120 +CONSTANT: EREMOTEIO 121 +CONSTANT: EDQUOT 122 +CONSTANT: ENOMEDIUM 123 +CONSTANT: EMEDIUMTYPE 124 +CONSTANT: ECANCELED 125 +CONSTANT: ENOKEY 126 +CONSTANT: EKEYEXPIRED 127 +CONSTANT: EKEYREVOKED 128 +CONSTANT: EKEYREJECTED 129 +CONSTANT: EOWNERDEAD 130 +CONSTANT: ENOTRECOVERABLE 131 diff --git a/basis/unix/solaris/authors.txt b/basis/unix/ffi/solaris/authors.txt similarity index 100% rename from basis/unix/solaris/authors.txt rename to basis/unix/ffi/solaris/authors.txt diff --git a/basis/unix/solaris/solaris.factor b/basis/unix/ffi/solaris/solaris.factor similarity index 97% rename from basis/unix/solaris/solaris.factor rename to basis/unix/ffi/solaris/solaris.factor index 1a1a7603f0..d641961a25 100644 --- a/basis/unix/solaris/solaris.factor +++ b/basis/unix/ffi/solaris/solaris.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2006 Patrick Mauritz. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.syntax system kernel layouts ; -IN: unix +IN: unix.ffi ! Solaris. @@ -52,7 +52,7 @@ STRUCT: sockaddr-in6 { addr uchar[16] } { scopeid uint } ; -: max-un-path 108 ; +CONSTANT: max-un-path 108 STRUCT: sockaddr-un { family ushort } diff --git a/basis/unix/debugger/tags.txt b/basis/unix/ffi/solaris/tags.txt similarity index 100% rename from basis/unix/debugger/tags.txt rename to basis/unix/ffi/solaris/tags.txt diff --git a/basis/unix/groups/groups.factor b/basis/unix/groups/groups.factor index 02d9f37023..a9b80002a8 100644 --- a/basis/unix/groups/groups.factor +++ b/basis/unix/groups/groups.factor @@ -4,10 +4,10 @@ USING: alien alien.c-types alien.strings io.encodings.utf8 io.backend.unix kernel math sequences splitting strings combinators.short-circuit byte-arrays combinators accessors math.parser fry assocs namespaces continuations -unix.users unix.utilities classes.struct ; +unix.users unix.utilities classes.struct unix ; IN: unix.groups -QUALIFIED: unix +QUALIFIED: unix.ffi QUALIFIED: grouping @@ -23,17 +23,21 @@ GENERIC: group-struct ( obj -- group/f ) gr_mem>> utf8 alien>strings ; : (group-struct) ( id -- group-struct id group-struct byte-array length void* ) - [ \ unix:group ] dip over 4096 + [ \ unix.ffi:group ] dip over 4096 [ ] keep f ; : check-group-struct ( group-struct ptr -- group-struct/f ) *void* [ drop f ] unless ; M: integer group-struct ( id -- group/f ) - (group-struct) [ unix:getgrgid_r unix:io-error ] keep check-group-struct ; + (group-struct) + [ [ unix.ffi:getgrgid_r ] unix-system-call io-error ] keep + check-group-struct ; M: string group-struct ( string -- group/f ) - (group-struct) [ unix:getgrnam_r unix:io-error ] keep check-group-struct ; + (group-struct) + [ [ unix.ffi:getgrnam_r ] unix-system-call io-error ] keep + check-group-struct ; : group-struct>group ( group-struct -- group ) [ \ group new ] dip @@ -64,8 +68,8 @@ PRIVATE> : (user-groups) ( string -- seq ) #! first group is -1337, legacy unix code - -1337 unix:NGROUPS_MAX [ 4 * ] keep - [ unix:getgrouplist unix:io-error ] 2keep + -1337 unix.ffi:NGROUPS_MAX [ 4 * ] keep + [ [ unix.ffi:getgrouplist ] unix-system-call io-error ] 2keep [ 4 tail-slice ] [ *int 1 - ] bi* >groups ; PRIVATE> @@ -79,7 +83,7 @@ M: integer user-groups ( id -- seq ) user-name (user-groups) ; : all-groups ( -- seq ) - [ unix:getgrent dup ] [ \ unix:group memory>struct group-struct>group ] produce nip ; + [ [ unix.ffi:getgrent ] unix-system-call dup ] [ \ unix.ffi:group memory>struct group-struct>group ] produce nip ; : ( -- assoc ) all-groups [ [ id>> ] keep ] H{ } map>assoc ; @@ -87,11 +91,11 @@ M: integer user-groups ( id -- seq ) : with-group-cache ( quot -- ) [ group-cache ] dip with-variable ; inline -: real-group-id ( -- id ) unix:getgid ; inline +: real-group-id ( -- id ) unix.ffi:getgid ; inline : real-group-name ( -- string ) real-group-id group-name ; inline -: effective-group-id ( -- string ) unix:getegid ; inline +: effective-group-id ( -- string ) unix.ffi:getegid ; inline : effective-group-name ( -- string ) effective-group-id group-name ; inline @@ -111,10 +115,10 @@ GENERIC: set-effective-group ( obj -- ) diff --git a/basis/unix/linux/linux.factor b/basis/unix/linux/linux.factor index 93bf621acd..10bf070e1a 100644 --- a/basis/unix/linux/linux.factor +++ b/basis/unix/linux/linux.factor @@ -1,241 +1,6 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types alien.syntax alien system classes.struct -unix.types ; -IN: unix - -! Linux. - -CONSTANT: MAXPATHLEN 1024 - -CONSTANT: O_RDONLY HEX: 0000 -CONSTANT: O_WRONLY HEX: 0001 -CONSTANT: O_RDWR HEX: 0002 -CONSTANT: O_CREAT HEX: 0040 -CONSTANT: O_EXCL HEX: 0080 -CONSTANT: O_NOCTTY HEX: 0100 -CONSTANT: O_TRUNC HEX: 0200 -CONSTANT: O_APPEND HEX: 0400 -CONSTANT: O_NONBLOCK HEX: 0800 - -ALIAS: O_NDELAY O_NONBLOCK - -CONSTANT: SOL_SOCKET 1 - -CONSTANT: FD_SETSIZE 1024 - -CONSTANT: SO_REUSEADDR 2 -CONSTANT: SO_OOBINLINE 10 -CONSTANT: SO_SNDTIMEO HEX: 15 -CONSTANT: SO_RCVTIMEO HEX: 14 - -CONSTANT: F_SETFD 2 -CONSTANT: FD_CLOEXEC 1 - -CONSTANT: F_SETFL 4 - -STRUCT: addrinfo - { flags int } - { family int } - { socktype int } - { protocol int } - { addrlen socklen_t } - { addr void* } - { canonname char* } - { next addrinfo* } ; - -STRUCT: sockaddr-in - { family ushort } - { port ushort } - { addr in_addr_t } - { unused longlong } ; - -STRUCT: sockaddr-in6 - { family ushort } - { port ushort } - { flowinfo uint } - { addr uchar[16] } - { scopeid uint } ; - -CONSTANT: max-un-path 108 - -STRUCT: sockaddr-un - { family ushort } - { path { char max-un-path } } ; - -CONSTANT: SOCK_STREAM 1 -CONSTANT: SOCK_DGRAM 2 - -CONSTANT: AF_UNSPEC 0 -CONSTANT: AF_UNIX 1 -CONSTANT: AF_INET 2 -CONSTANT: AF_INET6 10 - -ALIAS: PF_UNSPEC AF_UNSPEC -ALIAS: PF_UNIX AF_UNIX -ALIAS: PF_INET AF_INET -ALIAS: PF_INET6 AF_INET6 - -CONSTANT: IPPROTO_TCP 6 -CONSTANT: IPPROTO_UDP 17 - -CONSTANT: AI_PASSIVE 1 - -CONSTANT: SEEK_SET 0 -CONSTANT: SEEK_CUR 1 -CONSTANT: SEEK_END 2 - -STRUCT: passwd - { pw_name char* } - { pw_passwd char* } - { pw_uid uid_t } - { pw_gid gid_t } - { pw_gecos char* } - { pw_dir char* } - { pw_shell char* } ; - -! dirent64 -STRUCT: dirent - { d_ino ulonglong } - { d_off longlong } - { d_reclen ushort } - { d_type uchar } - { d_name char[256] } ; - -FUNCTION: int open64 ( char* path, int flags, int prot ) ; -FUNCTION: dirent* readdir64 ( DIR* dirp ) ; -FUNCTION: int readdir64_r ( void* dirp, dirent* entry, dirent** result ) ; +USING: system unix unix.ffi unix.ffi.linux ; +IN: unix.linux M: linux open-file [ open64 ] unix-system-call ; - -CONSTANT: EPERM 1 -CONSTANT: ENOENT 2 -CONSTANT: ESRCH 3 -CONSTANT: EINTR 4 -CONSTANT: EIO 5 -CONSTANT: ENXIO 6 -CONSTANT: E2BIG 7 -CONSTANT: ENOEXEC 8 -CONSTANT: EBADF 9 -CONSTANT: ECHILD 10 -CONSTANT: EAGAIN 11 -CONSTANT: ENOMEM 12 -CONSTANT: EACCES 13 -CONSTANT: EFAULT 14 -CONSTANT: ENOTBLK 15 -CONSTANT: EBUSY 16 -CONSTANT: EEXIST 17 -CONSTANT: EXDEV 18 -CONSTANT: ENODEV 19 -CONSTANT: ENOTDIR 20 -CONSTANT: EISDIR 21 -CONSTANT: EINVAL 22 -CONSTANT: ENFILE 23 -CONSTANT: EMFILE 24 -CONSTANT: ENOTTY 25 -CONSTANT: ETXTBSY 26 -CONSTANT: EFBIG 27 -CONSTANT: ENOSPC 28 -CONSTANT: ESPIPE 29 -CONSTANT: EROFS 30 -CONSTANT: EMLINK 31 -CONSTANT: EPIPE 32 -CONSTANT: EDOM 33 -CONSTANT: ERANGE 34 -CONSTANT: EDEADLK 35 -CONSTANT: ENAMETOOLONG 36 -CONSTANT: ENOLCK 37 -CONSTANT: ENOSYS 38 -CONSTANT: ENOTEMPTY 39 -CONSTANT: ELOOP 40 -ALIAS: EWOULDBLOCK EAGAIN -CONSTANT: ENOMSG 42 -CONSTANT: EIDRM 43 -CONSTANT: ECHRNG 44 -CONSTANT: EL2NSYNC 45 -CONSTANT: EL3HLT 46 -CONSTANT: EL3RST 47 -CONSTANT: ELNRNG 48 -CONSTANT: EUNATCH 49 -CONSTANT: ENOCSI 50 -CONSTANT: EL2HLT 51 -CONSTANT: EBADE 52 -CONSTANT: EBADR 53 -CONSTANT: EXFULL 54 -CONSTANT: ENOANO 55 -CONSTANT: EBADRQC 56 -CONSTANT: EBADSLT 57 -ALIAS: EDEADLOCK EDEADLK -CONSTANT: EBFONT 59 -CONSTANT: ENOSTR 60 -CONSTANT: ENODATA 61 -CONSTANT: ETIME 62 -CONSTANT: ENOSR 63 -CONSTANT: ENONET 64 -CONSTANT: ENOPKG 65 -CONSTANT: EREMOTE 66 -CONSTANT: ENOLINK 67 -CONSTANT: EADV 68 -CONSTANT: ESRMNT 69 -CONSTANT: ECOMM 70 -CONSTANT: EPROTO 71 -CONSTANT: EMULTIHOP 72 -CONSTANT: EDOTDOT 73 -CONSTANT: EBADMSG 74 -CONSTANT: EOVERFLOW 75 -CONSTANT: ENOTUNIQ 76 -CONSTANT: EBADFD 77 -CONSTANT: EREMCHG 78 -CONSTANT: ELIBACC 79 -CONSTANT: ELIBBAD 80 -CONSTANT: ELIBSCN 81 -CONSTANT: ELIBMAX 82 -CONSTANT: ELIBEXEC 83 -CONSTANT: EILSEQ 84 -CONSTANT: ERESTART 85 -CONSTANT: ESTRPIPE 86 -CONSTANT: EUSERS 87 -CONSTANT: ENOTSOCK 88 -CONSTANT: EDESTADDRREQ 89 -CONSTANT: EMSGSIZE 90 -CONSTANT: EPROTOTYPE 91 -CONSTANT: ENOPROTOOPT 92 -CONSTANT: EPROTONOSUPPORT 93 -CONSTANT: ESOCKTNOSUPPORT 94 -CONSTANT: EOPNOTSUPP 95 -CONSTANT: EPFNOSUPPORT 96 -CONSTANT: EAFNOSUPPORT 97 -CONSTANT: EADDRINUSE 98 -CONSTANT: EADDRNOTAVAIL 99 -CONSTANT: ENETDOWN 100 -CONSTANT: ENETUNREACH 101 -CONSTANT: ENETRESET 102 -CONSTANT: ECONNABORTED 103 -CONSTANT: ECONNRESET 104 -CONSTANT: ENOBUFS 105 -CONSTANT: EISCONN 106 -CONSTANT: ENOTCONN 107 -CONSTANT: ESHUTDOWN 108 -CONSTANT: ETOOMANYREFS 109 -CONSTANT: ETIMEDOUT 110 -CONSTANT: ECONNREFUSED 111 -CONSTANT: EHOSTDOWN 112 -CONSTANT: EHOSTUNREACH 113 -CONSTANT: EALREADY 114 -CONSTANT: EINPROGRESS 115 -CONSTANT: ESTALE 116 -CONSTANT: EUCLEAN 117 -CONSTANT: ENOTNAM 118 -CONSTANT: ENAVAIL 119 -CONSTANT: EISNAM 120 -CONSTANT: EREMOTEIO 121 -CONSTANT: EDQUOT 122 -CONSTANT: ENOMEDIUM 123 -CONSTANT: EMEDIUMTYPE 124 -CONSTANT: ECANCELED 125 -CONSTANT: ENOKEY 126 -CONSTANT: EKEYEXPIRED 127 -CONSTANT: EKEYREVOKED 128 -CONSTANT: EKEYREJECTED 129 -CONSTANT: EOWNERDEAD 130 -CONSTANT: ENOTRECOVERABLE 131 diff --git a/basis/unix/solaris/tags.txt b/basis/unix/solaris/tags.txt deleted file mode 100644 index 6bf68304bb..0000000000 --- a/basis/unix/solaris/tags.txt +++ /dev/null @@ -1 +0,0 @@ -unportable diff --git a/basis/unix/stat/macosx/macosx.factor b/basis/unix/stat/macosx/macosx.factor index a2104dcb33..4e6b2dfb21 100644 --- a/basis/unix/stat/macosx/macosx.factor +++ b/basis/unix/stat/macosx/macosx.factor @@ -1,5 +1,5 @@ USING: alien.c-types arrays accessors combinators classes.struct -alien.syntax unix.time unix.types ; +alien.syntax unix.time unix.types unix.ffi ; IN: unix.stat ! Mac OS X diff --git a/basis/unix/statfs/macosx/macosx.factor b/basis/unix/statfs/macosx/macosx.factor index e83d2d40a0..56c8989895 100644 --- a/basis/unix/statfs/macosx/macosx.factor +++ b/basis/unix/statfs/macosx/macosx.factor @@ -3,7 +3,7 @@ USING: alien.c-types io.encodings.utf8 io.encodings.string kernel sequences unix.stat accessors unix combinators math grouping system alien.strings math.bitwise alien.syntax -unix.types classes.struct ; +unix.types classes.struct unix.ffi ; IN: unix.statfs.macosx CONSTANT: MNT_RDONLY HEX: 00000001 diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index 86b8646bdd..4e77a41713 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -6,40 +6,9 @@ alien.syntax byte-arrays classes.struct combinators combinators.short-circuit combinators.smart continuations generalizations io kernel libc locals macros math namespaces sequences stack-checker strings system unix.time unix.types -vocabs vocabs.loader ; +vocabs vocabs.loader unix.ffi ; IN: unix -CONSTANT: PROT_NONE 0 -CONSTANT: PROT_READ 1 -CONSTANT: PROT_WRITE 2 -CONSTANT: PROT_EXEC 4 - -CONSTANT: MAP_FILE 0 -CONSTANT: MAP_SHARED 1 -CONSTANT: MAP_PRIVATE 2 - -CONSTANT: SEEK_SET 0 -CONSTANT: SEEK_CUR 1 -CONSTANT: SEEK_END 2 - -: MAP_FAILED ( -- alien ) -1 ; inline - -CONSTANT: NGROUPS_MAX 16 - -CONSTANT: DT_UNKNOWN 0 -CONSTANT: DT_FIFO 1 -CONSTANT: DT_CHR 2 -CONSTANT: DT_DIR 4 -CONSTANT: DT_BLK 6 -CONSTANT: DT_REG 8 -CONSTANT: DT_LNK 10 -CONSTANT: DT_SOCK 12 -CONSTANT: DT_WHT 14 - -LIBRARY: libc - -FUNCTION: char* strerror ( int errno ) ; - ERROR: unix-error errno message ; : (io-error) ( -- * ) errno dup strerror unix-error ; @@ -79,109 +48,14 @@ MACRO:: unix-system-call ( quot -- ) HOOK: open-file os ( path flags mode -- fd ) -<< - -{ - { [ os linux? ] [ "unix.linux" require ] } - { [ os bsd? ] [ "unix.bsd" require ] } - { [ os solaris? ] [ "unix.solaris" require ] } -} cond - -"debugger" vocab [ - "unix.debugger" require -] when - ->> - -STRUCT: group - { gr_name char* } - { gr_passwd char* } - { gr_gid int } - { gr_mem char** } ; - -FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen ) ; -FUNCTION: int bind ( int s, void* name, socklen_t namelen ) ; -FUNCTION: int chdir ( char* path ) ; -FUNCTION: int chmod ( char* path, mode_t mode ) ; -FUNCTION: int fchmod ( int fd, mode_t mode ) ; -FUNCTION: int chown ( char* path, uid_t owner, gid_t group ) ; -FUNCTION: int chroot ( char* path ) ; - -FUNCTION: int close ( int fd ) ; -FUNCTION: int closedir ( DIR* dirp ) ; - : close-file ( fd -- ) [ close ] unix-system-call drop ; -FUNCTION: int connect ( int s, void* name, socklen_t namelen ) ; -FUNCTION: int dup2 ( int oldd, int newd ) ; -! FUNCTION: int dup ( int oldd ) ; : _exit ( status -- * ) #! We throw to give this a terminating stack effect. int f "_exit" { int } alien-invoke "Exit failed" throw ; -FUNCTION: void endpwent ( ) ; -FUNCTION: int fchdir ( int fd ) ; -FUNCTION: int fchown ( int fd, uid_t owner, gid_t group ) ; -FUNCTION: int fcntl ( int fd, int cmd, int arg ) ; -FUNCTION: int flock ( int fd, int operation ) ; -FUNCTION: void freeaddrinfo ( addrinfo* ai ) ; -FUNCTION: int futimes ( int id, timeval[2] times ) ; -FUNCTION: char* gai_strerror ( int ecode ) ; -FUNCTION: int getaddrinfo ( char* hostname, char* servname, addrinfo* hints, addrinfo** res ) ; -FUNCTION: char* getcwd ( char* buf, size_t size ) ; -FUNCTION: pid_t getpid ; -FUNCTION: int getdtablesize ; -FUNCTION: gid_t getegid ; -FUNCTION: uid_t geteuid ; -FUNCTION: gid_t getgid ; -FUNCTION: char* getenv ( char* name ) ; - -FUNCTION: int getgrgid_r ( gid_t gid, group* grp, char* buffer, size_t bufsize, group** result ) ; -FUNCTION: int getgrnam_r ( char* name, group* grp, char* buffer, size_t bufsize, group** result ) ; -FUNCTION: passwd* getpwent ( ) ; -FUNCTION: passwd* getpwuid ( uid_t uid ) ; -FUNCTION: passwd* getpwnam ( char* login ) ; -FUNCTION: int getpwnam_r ( char* login, passwd* pwd, char* buffer, size_t bufsize, passwd** result ) ; -FUNCTION: int getgroups ( int gidsetlen, gid_t* gidset ) ; -FUNCTION: int getgrouplist ( char* name, int basegid, int* groups, int* ngroups ) ; -FUNCTION: int getrlimit ( int resource, rlimit* rlp ) ; -FUNCTION: int setrlimit ( int resource, rlimit* rlp ) ; - -FUNCTION: int getpriority ( int which, id_t who ) ; -FUNCTION: int setpriority ( int which, id_t who, int prio ) ; - -FUNCTION: int getrusage ( int who, rusage* r_usage ) ; - -FUNCTION: group* getgrent ; -FUNCTION: int gethostname ( char* name, int len ) ; -FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len ) ; -FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len ) ; -FUNCTION: uid_t getuid ; -FUNCTION: uint htonl ( uint n ) ; -FUNCTION: ushort htons ( ushort n ) ; -! FUNCTION: int issetugid ; -FUNCTION: int ioctl ( int fd, ulong request, char* argp ) ; -FUNCTION: int lchown ( char* path, uid_t owner, gid_t group ) ; -FUNCTION: int listen ( int s, int backlog ) ; -FUNCTION: off_t lseek ( int fildes, off_t offset, int whence ) ; -FUNCTION: int mkdir ( char* path, mode_t mode ) ; -FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset ) ; -FUNCTION: int munmap ( void* addr, size_t len ) ; -FUNCTION: uint ntohl ( uint n ) ; -FUNCTION: ushort ntohs ( ushort n ) ; -FUNCTION: int shutdown ( int fd, int how ) ; - -FUNCTION: int open ( char* path, int flags, int prot ) ; M: unix open-file [ open ] unix-system-call ; -FUNCTION: DIR* opendir ( char* path ) ; - -STRUCT: utimbuf - { actime time_t } - { modtime time_t } ; - -FUNCTION: int utime ( char* path, utimbuf* buf ) ; - : touch ( filename -- ) f [ utime ] unix-system-call drop ; : change-file-times ( filename access modification -- ) @@ -190,50 +64,18 @@ FUNCTION: int utime ( char* path, utimbuf* buf ) ; swap >>actime [ utime ] unix-system-call drop ; -FUNCTION: int pclose ( void* file ) ; -FUNCTION: int pipe ( int* filedes ) ; -FUNCTION: void* popen ( char* command, char* type ) ; -FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ; - -FUNCTION: dirent* readdir ( DIR* dirp ) ; -FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result ) ; -FUNCTION: ssize_t readlink ( char* path, char* buf, size_t bufsize ) ; - -CONSTANT: PATH_MAX 1024 - : read-symbolic-link ( path -- path ) PATH_MAX dup [ PATH_MAX [ readlink ] unix-system-call ] dip swap head-slice >string ; -FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags ) ; -FUNCTION: ssize_t recvfrom ( int s, void* buf, size_t nbytes, int flags, sockaddr-in* from, socklen_t* fromlen ) ; -FUNCTION: int rename ( char* from, char* to ) ; -FUNCTION: int rmdir ( char* path ) ; -FUNCTION: int select ( int nfds, void* readfds, void* writefds, void* exceptfds, timeval* timeout ) ; -FUNCTION: ssize_t sendto ( int s, void* buf, size_t len, int flags, sockaddr-in* to, socklen_t tolen ) ; -FUNCTION: int setenv ( char* name, char* value, int overwrite ) ; -FUNCTION: int unsetenv ( char* name ) ; -FUNCTION: int setegid ( gid_t egid ) ; -FUNCTION: int seteuid ( uid_t euid ) ; -FUNCTION: int setgid ( gid_t gid ) ; -FUNCTION: int setgroups ( int ngroups, gid_t* gidset ) ; -FUNCTION: int setregid ( gid_t rgid, gid_t egid ) ; -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: int symlink ( char* path1, char* path2 ) ; -FUNCTION: int link ( char* path1, char* path2 ) ; -FUNCTION: int system ( char* command ) ; - -FUNCTION: int unlink ( char* path ) ; - : unlink-file ( path -- ) [ unlink ] unix-system-call drop ; -FUNCTION: int utimes ( char* path, timeval[2] times ) ; +<< -FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ; +"debugger" vocab [ + "unix.debugger" require +] when -"librt" "librt.so" "cdecl" add-library +>> diff --git a/basis/unix/users/users.factor b/basis/unix/users/users.factor index 09119ff0cc..b279069c59 100644 --- a/basis/unix/users/users.factor +++ b/basis/unix/users/users.factor @@ -4,9 +4,9 @@ USING: alien alien.c-types alien.strings io.encodings.utf8 io.backend.unix kernel math sequences splitting strings combinators.short-circuit grouping byte-arrays combinators accessors math.parser fry assocs namespaces continuations -vocabs.loader system classes.struct ; +vocabs.loader system classes.struct unix ; IN: unix.users -QUALIFIED: unix +QUALIFIED: unix.ffi TUPLE: passwd user-name password uid gid gecos dir shell ; @@ -31,13 +31,13 @@ M: unix passwd>new-passwd ( passwd -- seq ) } cleave ; : with-pwent ( quot -- ) - [ unix:endpwent ] [ ] cleanup ; inline + [ unix.ffi:endpwent ] [ ] cleanup ; inline PRIVATE> : all-users ( -- seq ) [ - [ unix:getpwent dup ] [ unix:passwd memory>struct passwd>new-passwd ] produce nip + [ unix.ffi:getpwent dup ] [ unix.ffi:passwd memory>struct passwd>new-passwd ] produce nip ] with-pwent ; SYMBOL: user-cache @@ -52,10 +52,10 @@ GENERIC: user-passwd ( obj -- passwd/f ) M: integer user-passwd ( id -- passwd/f ) user-cache get - [ at ] [ unix:getpwuid [ unix:passwd memory>struct passwd>new-passwd ] [ f ] if* ] if* ; + [ at ] [ unix.ffi:getpwuid [ unix.ffi:passwd memory>struct passwd>new-passwd ] [ f ] if* ] if* ; M: string user-passwd ( string -- passwd/f ) - unix:getpwnam dup [ unix:passwd memory>struct passwd>new-passwd ] when ; + unix.ffi:getpwnam dup [ unix.ffi:passwd memory>struct passwd>new-passwd ] when ; : user-name ( id -- string ) dup user-passwd @@ -65,13 +65,13 @@ M: string user-passwd ( string -- passwd/f ) user-passwd uid>> ; : real-user-id ( -- id ) - unix:getuid ; inline + unix.ffi:getuid ; inline : real-user-name ( -- string ) real-user-id user-name ; inline : effective-user-id ( -- id ) - unix:geteuid ; inline + unix.ffi:geteuid ; inline : effective-user-name ( -- string ) effective-user-id user-name ; inline @@ -93,10 +93,10 @@ GENERIC: set-effective-user ( string/id -- )