Handle EINTR in a lot of cases where it wasn't handled before. Split off unix into unix.ffi and unix.
parent
bb2f455747
commit
8d952277a2
|
@ -3,7 +3,7 @@
|
||||||
USING: alien alien.c-types alien.data alien.strings
|
USING: alien alien.c-types alien.data alien.strings
|
||||||
alien.syntax kernel layouts sequences system unix
|
alien.syntax kernel layouts sequences system unix
|
||||||
environment io.encodings.utf8 unix.utilities vocabs.loader
|
environment io.encodings.utf8 unix.utilities vocabs.loader
|
||||||
combinators alien.accessors ;
|
combinators alien.accessors unix.ffi ;
|
||||||
IN: environment.unix
|
IN: environment.unix
|
||||||
|
|
||||||
HOOK: environ os ( -- void* )
|
HOOK: environ os ( -- void* )
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types alien.syntax generic assocs kernel
|
USING: alien alien.c-types alien.syntax generic assocs kernel
|
||||||
kernel.private math io.ports sequences strings sbufs threads
|
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
|
continuations system libc namespaces make io.timeouts
|
||||||
io.encodings.utf8 destructors destructors.private accessors
|
io.encodings.utf8 destructors destructors.private accessors
|
||||||
summary combinators locals unix.time unix.types fry
|
summary combinators locals unix.time unix.types fry
|
||||||
|
|
|
@ -4,7 +4,7 @@ USING: accessors alien.c-types alien.strings combinators
|
||||||
continuations destructors fry io io.backend io.backend.unix
|
continuations destructors fry io io.backend io.backend.unix
|
||||||
io.directories io.encodings.binary io.encodings.utf8 io.files
|
io.directories io.encodings.binary io.encodings.utf8 io.files
|
||||||
io.pathnames io.files.types kernel math.bitwise sequences system
|
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
|
IN: io.directories.unix
|
||||||
|
|
||||||
: touch-mode ( -- n )
|
: touch-mode ( -- n )
|
||||||
|
|
|
@ -26,7 +26,7 @@ available-space free-space used-space total-space ;
|
||||||
HOOK: file-system-info os ( path -- file-system-info )
|
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" ] }
|
{ [ os windows? ] [ "io.files.info.windows" ] }
|
||||||
} cond require
|
} cond require
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors kernel system math math.bitwise strings arrays
|
USING: accessors alien.c-types arrays calendar calendar.unix
|
||||||
sequences combinators combinators.short-circuit alien.c-types
|
classes.struct combinators combinators.short-circuit io.backend
|
||||||
vocabs.loader calendar calendar.unix io.files.info
|
io.directories io.files.info io.files.types kernel literals
|
||||||
io.files.types io.backend io.directories unix unix.stat
|
math math.bitwise sequences specialized-arrays strings system
|
||||||
unix.time unix.users unix.groups classes.struct
|
unix unix.ffi unix.groups unix.stat unix.time unix.users
|
||||||
specialized-arrays literals ;
|
vocabs.loader ;
|
||||||
SPECIALIZED-ARRAY: timeval
|
|
||||||
IN: io.files.info.unix
|
IN: io.files.info.unix
|
||||||
|
SPECIALIZED-ARRAY: timeval
|
||||||
|
|
||||||
TUPLE: unix-file-system-info < file-system-info
|
TUPLE: unix-file-system-info < file-system-info
|
||||||
block-size preferred-block-size
|
block-size preferred-block-size
|
||||||
|
@ -286,3 +286,5 @@ PRIVATE>
|
||||||
{ +regular-file+ [ file-type>executable ] }
|
{ +regular-file+ [ file-type>executable ] }
|
||||||
[ drop file-type>executable ]
|
[ drop file-type>executable ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
"io.files.info.unix." os name>> append require
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io.backend io.files.links system unix io.pathnames kernel
|
USING: io.backend io.files io.files.links io.pathnames kernel
|
||||||
io.files sequences ;
|
sequences system unix unix.ffi ;
|
||||||
IN: io.files.links.unix
|
IN: io.files.links.unix
|
||||||
|
|
||||||
M: unix make-link ( path1 path2 -- )
|
M: unix make-link ( path1 path2 -- )
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: unix byte-arrays kernel io.backend.unix math.bitwise
|
USING: unix byte-arrays kernel io.backend.unix math.bitwise
|
||||||
io.ports io.files io.files.private io.pathnames environment
|
io.ports io.files io.files.private io.pathnames environment
|
||||||
destructors system ;
|
destructors system unix.ffi ;
|
||||||
IN: io.files.unix
|
IN: io.files.unix
|
||||||
|
|
||||||
M: unix cwd ( -- path )
|
M: unix cwd ( -- path )
|
||||||
|
|
|
@ -5,7 +5,7 @@ continuations environment io io.backend io.backend.unix
|
||||||
io.files io.files.private io.files.unix io.launcher
|
io.files io.files.private io.files.unix io.launcher
|
||||||
io.launcher.unix.parser io.pathnames io.ports kernel math
|
io.launcher.unix.parser io.pathnames io.ports kernel math
|
||||||
namespaces sequences strings system threads unix
|
namespaces sequences strings system threads unix
|
||||||
unix.process ;
|
unix.process unix.ffi ;
|
||||||
IN: io.launcher.unix
|
IN: io.launcher.unix
|
||||||
|
|
||||||
: get-arguments ( process -- seq )
|
: get-arguments ( process -- seq )
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types system kernel unix math sequences
|
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
|
QUALIFIED: io.pipes
|
||||||
SPECIALIZED-ARRAY: int
|
SPECIALIZED-ARRAY: int
|
||||||
IN: io.pipes.unix
|
IN: io.pipes.unix
|
||||||
|
|
|
@ -6,7 +6,8 @@ alien.strings libc continuations destructors openssl
|
||||||
openssl.libcrypto openssl.libssl io io.files io.ports
|
openssl.libcrypto openssl.libssl io io.files io.ports
|
||||||
io.backend.unix io.sockets.unix io.encodings.ascii io.buffers
|
io.backend.unix io.sockets.unix io.encodings.ascii io.buffers
|
||||||
io.sockets io.sockets.private io.sockets.secure
|
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 ;
|
FROM: io.ports => shutdown ;
|
||||||
IN: io.sockets.secure.unix
|
IN: io.sockets.secure.unix
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ IN: io.sockets
|
||||||
|
|
||||||
<< {
|
<< {
|
||||||
{ [ os windows? ] [ "windows.winsock" ] }
|
{ [ os windows? ] [ "windows.winsock" ] }
|
||||||
{ [ os unix? ] [ "unix" ] }
|
{ [ os unix? ] [ "unix.ffi" ] }
|
||||||
} cond use-vocab >>
|
} cond use-vocab >>
|
||||||
|
|
||||||
! Addressing
|
! Addressing
|
||||||
|
|
|
@ -5,7 +5,7 @@ threads sequences byte-arrays io.binary io.backend.unix
|
||||||
io.streams.duplex io.backend io.pathnames io.sockets.private
|
io.streams.duplex io.backend io.pathnames io.sockets.private
|
||||||
io.files.private io.encodings.utf8 math.parser continuations
|
io.files.private io.encodings.utf8 math.parser continuations
|
||||||
libc combinators system accessors destructors unix locals init
|
libc combinators system accessors destructors unix locals init
|
||||||
classes.struct alien.data ;
|
classes.struct alien.data unix.ffi ;
|
||||||
|
|
||||||
EXCLUDE: namespaces => bind ;
|
EXCLUDE: namespaces => bind ;
|
||||||
EXCLUDE: io => read write ;
|
EXCLUDE: io => read write ;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: debugger prettyprint accessors unix kernel ;
|
USING: accessors debugger io kernel prettyprint unix ;
|
||||||
FROM: io => write print nl ;
|
|
||||||
IN: unix.debugger
|
IN: unix.debugger
|
||||||
|
|
||||||
M: unix-error error.
|
M: unix-error error.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types alien.syntax classes.struct combinators
|
USING: alien.c-types alien.syntax classes.struct combinators
|
||||||
system unix.types vocabs.loader ;
|
system unix.types vocabs.loader ;
|
||||||
IN: unix
|
IN: unix.ffi
|
||||||
|
|
||||||
CONSTANT: MAXPATHLEN 1024
|
CONSTANT: MAXPATHLEN 1024
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ CONSTANT: SEEK_CUR 1
|
||||||
CONSTANT: SEEK_END 2
|
CONSTANT: SEEK_END 2
|
||||||
|
|
||||||
os {
|
os {
|
||||||
{ macosx [ "unix.bsd.macosx" require ] }
|
{ macosx [ "unix.ffi.bsd.macosx" require ] }
|
||||||
{ freebsd [ "unix.bsd.freebsd" require ] }
|
{ freebsd [ "unix.ffi.bsd.freebsd" require ] }
|
||||||
{ openbsd [ "unix.bsd.openbsd" require ] }
|
{ openbsd [ "unix.ffi.bsd.openbsd" require ] }
|
||||||
{ netbsd [ "unix.bsd.netbsd" require ] }
|
{ netbsd [ "unix.ffi.bsd.netbsd" require ] }
|
||||||
} case
|
} case
|
|
@ -1,5 +1,5 @@
|
||||||
USING: alien.c-types alien.syntax classes.struct unix.types ;
|
USING: alien.c-types alien.syntax classes.struct unix.types ;
|
||||||
IN: unix
|
IN: unix.ffi
|
||||||
|
|
||||||
CONSTANT: FD_SETSIZE 1024
|
CONSTANT: FD_SETSIZE 1024
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
USING: alien.c-types alien.syntax unix.time unix.types
|
USING: alien alien.c-types alien.libraries alien.syntax
|
||||||
unix.types.macosx classes.struct ;
|
classes.struct combinators kernel system unix unix.time
|
||||||
IN: unix
|
unix.types vocabs vocabs.loader ;
|
||||||
|
IN: unix.ffi
|
||||||
|
|
||||||
CONSTANT: FD_SETSIZE 1024
|
CONSTANT: FD_SETSIZE 1024
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: alien.syntax alien.c-types math vocabs.loader
|
USING: alien.syntax alien.c-types math vocabs.loader
|
||||||
classes.struct unix.types ;
|
classes.struct unix.types ;
|
||||||
IN: unix
|
IN: unix.ffi
|
||||||
|
|
||||||
CONSTANT: FD_SETSIZE 256
|
CONSTANT: FD_SETSIZE 256
|
||||||
|
|
||||||
|
@ -138,4 +138,4 @@ CONSTANT: _SS_MAXSIZE 128
|
||||||
: _SS_PAD2SIZE ( -- n )
|
: _SS_PAD2SIZE ( -- n )
|
||||||
_SS_MAXSIZE 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE - ; inline
|
_SS_MAXSIZE 2 - _SS_PAD1SIZE - _SS_ALIGNSIZE - ; inline
|
||||||
|
|
||||||
"unix.bsd.netbsd.structs" require
|
"unix.ffi.bsd.netbsd.structs" require
|
|
@ -1,5 +1,5 @@
|
||||||
USING: alien.c-types alien.syntax classes.struct unix.types ;
|
USING: alien.c-types alien.syntax classes.struct unix.types ;
|
||||||
IN: unix
|
IN: unix.ffi
|
||||||
|
|
||||||
CONSTANT: FD_SETSIZE 1024
|
CONSTANT: FD_SETSIZE 1024
|
||||||
|
|
|
@ -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 <alien> ; 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
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -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
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2006 Patrick Mauritz.
|
! Copyright (C) 2006 Patrick Mauritz.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types alien.syntax system kernel layouts ;
|
USING: alien.c-types alien.syntax system kernel layouts ;
|
||||||
IN: unix
|
IN: unix.ffi
|
||||||
|
|
||||||
! Solaris.
|
! Solaris.
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ STRUCT: sockaddr-in6
|
||||||
{ addr uchar[16] }
|
{ addr uchar[16] }
|
||||||
{ scopeid uint } ;
|
{ scopeid uint } ;
|
||||||
|
|
||||||
: max-un-path 108 ;
|
CONSTANT: max-un-path 108
|
||||||
|
|
||||||
STRUCT: sockaddr-un
|
STRUCT: sockaddr-un
|
||||||
{ family ushort }
|
{ family ushort }
|
|
@ -4,10 +4,10 @@ USING: alien alien.c-types alien.strings io.encodings.utf8
|
||||||
io.backend.unix kernel math sequences splitting strings
|
io.backend.unix kernel math sequences splitting strings
|
||||||
combinators.short-circuit byte-arrays combinators
|
combinators.short-circuit byte-arrays combinators
|
||||||
accessors math.parser fry assocs namespaces continuations
|
accessors math.parser fry assocs namespaces continuations
|
||||||
unix.users unix.utilities classes.struct ;
|
unix.users unix.utilities classes.struct unix ;
|
||||||
IN: unix.groups
|
IN: unix.groups
|
||||||
|
|
||||||
QUALIFIED: unix
|
QUALIFIED: unix.ffi
|
||||||
|
|
||||||
QUALIFIED: grouping
|
QUALIFIED: grouping
|
||||||
|
|
||||||
|
@ -23,17 +23,21 @@ GENERIC: group-struct ( obj -- group/f )
|
||||||
gr_mem>> utf8 alien>strings ;
|
gr_mem>> utf8 alien>strings ;
|
||||||
|
|
||||||
: (group-struct) ( id -- group-struct id group-struct byte-array length void* )
|
: (group-struct) ( id -- group-struct id group-struct byte-array length void* )
|
||||||
[ \ unix:group <struct> ] dip over 4096
|
[ \ unix.ffi:group <struct> ] dip over 4096
|
||||||
[ <byte-array> ] keep f <void*> ;
|
[ <byte-array> ] keep f <void*> ;
|
||||||
|
|
||||||
: check-group-struct ( group-struct ptr -- group-struct/f )
|
: check-group-struct ( group-struct ptr -- group-struct/f )
|
||||||
*void* [ drop f ] unless ;
|
*void* [ drop f ] unless ;
|
||||||
|
|
||||||
M: integer group-struct ( id -- group/f )
|
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 )
|
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-struct>group ( group-struct -- group )
|
||||||
[ \ group new ] dip
|
[ \ group new ] dip
|
||||||
|
@ -64,8 +68,8 @@ PRIVATE>
|
||||||
|
|
||||||
: (user-groups) ( string -- seq )
|
: (user-groups) ( string -- seq )
|
||||||
#! first group is -1337, legacy unix code
|
#! first group is -1337, legacy unix code
|
||||||
-1337 unix:NGROUPS_MAX [ 4 * <byte-array> ] keep
|
-1337 unix.ffi:NGROUPS_MAX [ 4 * <byte-array> ] keep
|
||||||
<int> [ unix:getgrouplist unix:io-error ] 2keep
|
<int> [ [ unix.ffi:getgrouplist ] unix-system-call io-error ] 2keep
|
||||||
[ 4 tail-slice ] [ *int 1 - ] bi* >groups ;
|
[ 4 tail-slice ] [ *int 1 - ] bi* >groups ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
@ -79,7 +83,7 @@ M: integer user-groups ( id -- seq )
|
||||||
user-name (user-groups) ;
|
user-name (user-groups) ;
|
||||||
|
|
||||||
: all-groups ( -- seq )
|
: 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 ;
|
||||||
|
|
||||||
: <group-cache> ( -- assoc )
|
: <group-cache> ( -- assoc )
|
||||||
all-groups [ [ id>> ] keep ] H{ } map>assoc ;
|
all-groups [ [ id>> ] keep ] H{ } map>assoc ;
|
||||||
|
@ -87,11 +91,11 @@ M: integer user-groups ( id -- seq )
|
||||||
: with-group-cache ( quot -- )
|
: with-group-cache ( quot -- )
|
||||||
[ <group-cache> group-cache ] dip with-variable ; inline
|
[ <group-cache> 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
|
: 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-name ( -- string )
|
||||||
effective-group-id group-name ; inline
|
effective-group-id group-name ; inline
|
||||||
|
@ -111,10 +115,10 @@ GENERIC: set-effective-group ( obj -- )
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (set-real-group) ( id -- )
|
: (set-real-group) ( id -- )
|
||||||
unix:setgid unix:io-error ; inline
|
[ unix.ffi:setgid ] unix-system-call io-error ; inline
|
||||||
|
|
||||||
: (set-effective-group) ( id -- )
|
: (set-effective-group) ( id -- )
|
||||||
unix:setegid unix:io-error ; inline
|
[ unix.ffi:setegid ] unix-system-call io-error ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -1,241 +1,6 @@
|
||||||
! Copyright (C) 2005, 2008 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types alien.syntax alien system classes.struct
|
USING: system unix unix.ffi unix.ffi.linux ;
|
||||||
unix.types ;
|
IN: unix.linux
|
||||||
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 ) ;
|
|
||||||
|
|
||||||
M: linux open-file [ open64 ] unix-system-call ;
|
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
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
unportable
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: alien.c-types arrays accessors combinators classes.struct
|
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
|
IN: unix.stat
|
||||||
|
|
||||||
! Mac OS X
|
! Mac OS X
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: alien.c-types io.encodings.utf8 io.encodings.string
|
USING: alien.c-types io.encodings.utf8 io.encodings.string
|
||||||
kernel sequences unix.stat accessors unix combinators math
|
kernel sequences unix.stat accessors unix combinators math
|
||||||
grouping system alien.strings math.bitwise alien.syntax
|
grouping system alien.strings math.bitwise alien.syntax
|
||||||
unix.types classes.struct ;
|
unix.types classes.struct unix.ffi ;
|
||||||
IN: unix.statfs.macosx
|
IN: unix.statfs.macosx
|
||||||
|
|
||||||
CONSTANT: MNT_RDONLY HEX: 00000001
|
CONSTANT: MNT_RDONLY HEX: 00000001
|
||||||
|
|
|
@ -6,40 +6,9 @@ alien.syntax byte-arrays classes.struct combinators
|
||||||
combinators.short-circuit combinators.smart continuations
|
combinators.short-circuit combinators.smart continuations
|
||||||
generalizations io kernel libc locals macros math namespaces
|
generalizations io kernel libc locals macros math namespaces
|
||||||
sequences stack-checker strings system unix.time unix.types
|
sequences stack-checker strings system unix.time unix.types
|
||||||
vocabs vocabs.loader ;
|
vocabs vocabs.loader unix.ffi ;
|
||||||
IN: unix
|
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 <alien> ; 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 ;
|
ERROR: unix-error errno message ;
|
||||||
|
|
||||||
: (io-error) ( -- * ) errno dup strerror unix-error ;
|
: (io-error) ( -- * ) errno dup strerror unix-error ;
|
||||||
|
@ -79,109 +48,14 @@ MACRO:: unix-system-call ( quot -- )
|
||||||
|
|
||||||
HOOK: open-file os ( path flags mode -- fd )
|
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 ;
|
: 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 -- * )
|
: _exit ( status -- * )
|
||||||
#! We throw to give this a terminating stack effect.
|
#! We throw to give this a terminating stack effect.
|
||||||
int f "_exit" { int } alien-invoke "Exit failed" throw ;
|
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 ;
|
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 ;
|
: touch ( filename -- ) f [ utime ] unix-system-call drop ;
|
||||||
|
|
||||||
: change-file-times ( filename access modification -- )
|
: change-file-times ( filename access modification -- )
|
||||||
|
@ -190,50 +64,18 @@ FUNCTION: int utime ( char* path, utimbuf* buf ) ;
|
||||||
swap >>actime
|
swap >>actime
|
||||||
[ utime ] unix-system-call drop ;
|
[ 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 )
|
: read-symbolic-link ( path -- path )
|
||||||
PATH_MAX <byte-array> dup [
|
PATH_MAX <byte-array> dup [
|
||||||
PATH_MAX
|
PATH_MAX
|
||||||
[ readlink ] unix-system-call
|
[ readlink ] unix-system-call
|
||||||
] dip swap head-slice >string ;
|
] 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 ;
|
: 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
|
>>
|
||||||
|
|
|
@ -4,9 +4,9 @@ USING: alien alien.c-types alien.strings io.encodings.utf8
|
||||||
io.backend.unix kernel math sequences splitting strings
|
io.backend.unix kernel math sequences splitting strings
|
||||||
combinators.short-circuit grouping byte-arrays combinators
|
combinators.short-circuit grouping byte-arrays combinators
|
||||||
accessors math.parser fry assocs namespaces continuations
|
accessors math.parser fry assocs namespaces continuations
|
||||||
vocabs.loader system classes.struct ;
|
vocabs.loader system classes.struct unix ;
|
||||||
IN: unix.users
|
IN: unix.users
|
||||||
QUALIFIED: unix
|
QUALIFIED: unix.ffi
|
||||||
|
|
||||||
TUPLE: passwd user-name password uid gid gecos dir shell ;
|
TUPLE: passwd user-name password uid gid gecos dir shell ;
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ M: unix passwd>new-passwd ( passwd -- seq )
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: with-pwent ( quot -- )
|
: with-pwent ( quot -- )
|
||||||
[ unix:endpwent ] [ ] cleanup ; inline
|
[ unix.ffi:endpwent ] [ ] cleanup ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: all-users ( -- seq )
|
: 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 ;
|
] with-pwent ;
|
||||||
|
|
||||||
SYMBOL: user-cache
|
SYMBOL: user-cache
|
||||||
|
@ -52,10 +52,10 @@ GENERIC: user-passwd ( obj -- passwd/f )
|
||||||
|
|
||||||
M: integer user-passwd ( id -- passwd/f )
|
M: integer user-passwd ( id -- passwd/f )
|
||||||
user-cache get
|
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 )
|
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 )
|
: user-name ( id -- string )
|
||||||
dup user-passwd
|
dup user-passwd
|
||||||
|
@ -65,13 +65,13 @@ M: string user-passwd ( string -- passwd/f )
|
||||||
user-passwd uid>> ;
|
user-passwd uid>> ;
|
||||||
|
|
||||||
: real-user-id ( -- id )
|
: real-user-id ( -- id )
|
||||||
unix:getuid ; inline
|
unix.ffi:getuid ; inline
|
||||||
|
|
||||||
: real-user-name ( -- string )
|
: real-user-name ( -- string )
|
||||||
real-user-id user-name ; inline
|
real-user-id user-name ; inline
|
||||||
|
|
||||||
: effective-user-id ( -- id )
|
: effective-user-id ( -- id )
|
||||||
unix:geteuid ; inline
|
unix.ffi:geteuid ; inline
|
||||||
|
|
||||||
: effective-user-name ( -- string )
|
: effective-user-name ( -- string )
|
||||||
effective-user-id user-name ; inline
|
effective-user-id user-name ; inline
|
||||||
|
@ -93,10 +93,10 @@ GENERIC: set-effective-user ( string/id -- )
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (set-real-user) ( id -- )
|
: (set-real-user) ( id -- )
|
||||||
unix:setuid unix:io-error ; inline
|
[ unix.ffi:setuid ] unix-system-call io-error ; inline
|
||||||
|
|
||||||
: (set-effective-user) ( id -- )
|
: (set-effective-user) ( id -- )
|
||||||
unix:seteuid unix:io-error ; inline
|
[ unix.ffi:seteuid ] unix-system-call io-error ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue