Merge branch 'master' of git://factorcode.org/git/factor
commit
1782880f8c
|
@ -42,6 +42,7 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/syslimits.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,6 +147,7 @@ void unix_constants()
|
||||||
constant(PROT_WRITE);
|
constant(PROT_WRITE);
|
||||||
constant(MAP_FILE);
|
constant(MAP_FILE);
|
||||||
constant(MAP_SHARED);
|
constant(MAP_SHARED);
|
||||||
|
constant(PATH_MAX);
|
||||||
grovel(pid_t);
|
grovel(pid_t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: io.backend io.files.private io hashtables kernel math
|
USING: io.backend io.files.private io hashtables kernel math
|
||||||
memory namespaces sequences strings assocs arrays definitions
|
memory namespaces sequences strings assocs arrays definitions
|
||||||
system combinators splitting sbufs continuations io.encodings
|
system combinators splitting sbufs continuations io.encodings
|
||||||
io.encodings.binary init ;
|
io.encodings.binary init accessors ;
|
||||||
IN: io.files
|
IN: io.files
|
||||||
|
|
||||||
HOOK: (file-reader) io-backend ( path -- stream )
|
HOOK: (file-reader) io-backend ( path -- stream )
|
||||||
|
@ -145,8 +145,17 @@ PRIVATE>
|
||||||
TUPLE: file-info type size permissions modified ;
|
TUPLE: file-info type size permissions modified ;
|
||||||
|
|
||||||
HOOK: file-info io-backend ( path -- info )
|
HOOK: file-info io-backend ( path -- info )
|
||||||
|
|
||||||
|
! Symlinks
|
||||||
HOOK: link-info io-backend ( path -- info )
|
HOOK: link-info io-backend ( path -- info )
|
||||||
|
|
||||||
|
HOOK: make-link io-backend ( path1 path2 -- )
|
||||||
|
|
||||||
|
HOOK: read-link io-backend ( path -- info )
|
||||||
|
|
||||||
|
: copy-link ( path1 path2 -- )
|
||||||
|
>r read-link r> make-link ;
|
||||||
|
|
||||||
SYMBOL: +regular-file+
|
SYMBOL: +regular-file+
|
||||||
SYMBOL: +directory+
|
SYMBOL: +directory+
|
||||||
SYMBOL: +character-device+
|
SYMBOL: +character-device+
|
||||||
|
@ -218,14 +227,14 @@ HOOK: delete-file io-backend ( path -- )
|
||||||
|
|
||||||
HOOK: delete-directory io-backend ( path -- )
|
HOOK: delete-directory io-backend ( path -- )
|
||||||
|
|
||||||
: (delete-tree) ( path dir? -- )
|
|
||||||
[
|
|
||||||
dup directory* [ (delete-tree) ] assoc-each
|
|
||||||
delete-directory
|
|
||||||
] [ delete-file ] if ;
|
|
||||||
|
|
||||||
: delete-tree ( path -- )
|
: delete-tree ( path -- )
|
||||||
dup directory? (delete-tree) ;
|
dup link-info type>> +directory+ = [
|
||||||
|
dup directory over [
|
||||||
|
[ first delete-tree ] each
|
||||||
|
] with-directory delete-directory
|
||||||
|
] [
|
||||||
|
delete-file
|
||||||
|
] if ;
|
||||||
|
|
||||||
: to-directory over file-name append-path ;
|
: to-directory over file-name append-path ;
|
||||||
|
|
||||||
|
@ -258,13 +267,16 @@ M: object copy-file
|
||||||
DEFER: copy-tree-into
|
DEFER: copy-tree-into
|
||||||
|
|
||||||
: copy-tree ( from to -- )
|
: copy-tree ( from to -- )
|
||||||
over directory? [
|
over link-info type>>
|
||||||
>r dup directory swap r> [
|
{
|
||||||
>r swap first append-path r> copy-tree-into
|
{ +symbolic-link+ [ copy-link ] }
|
||||||
] 2curry each
|
{ +directory+ [
|
||||||
] [
|
>r dup directory r> rot [
|
||||||
copy-file
|
[ >r first r> copy-tree-into ] curry each
|
||||||
] if ;
|
] with-directory
|
||||||
|
] }
|
||||||
|
[ drop copy-file ]
|
||||||
|
} case ;
|
||||||
|
|
||||||
: copy-tree-into ( from to -- )
|
: copy-tree-into ( from to -- )
|
||||||
to-directory copy-tree ;
|
to-directory copy-tree ;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: io.backend io.nonblocking io.unix.backend io.files io
|
USING: io.backend io.nonblocking io.unix.backend io.files io
|
||||||
unix unix.stat unix.time kernel math continuations
|
unix unix.stat unix.time kernel math continuations
|
||||||
math.bitfields byte-arrays alien combinators calendar
|
math.bitfields byte-arrays alien combinators calendar
|
||||||
io.encodings.binary ;
|
io.encodings.binary accessors sequences strings ;
|
||||||
|
|
||||||
IN: io.unix.files
|
IN: io.unix.files
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ M: unix-io copy-file ( from to -- )
|
||||||
{ [ dup S_ISLNK ] [ +symbolic-link+ ] }
|
{ [ dup S_ISLNK ] [ +symbolic-link+ ] }
|
||||||
{ [ dup S_ISSOCK ] [ +socket+ ] }
|
{ [ dup S_ISSOCK ] [ +socket+ ] }
|
||||||
{ [ t ] [ +unknown+ ] }
|
{ [ t ] [ +unknown+ ] }
|
||||||
} cond nip ;
|
} cond nip ;
|
||||||
|
|
||||||
: stat>file-info ( stat -- info )
|
: stat>file-info ( stat -- info )
|
||||||
{
|
{
|
||||||
|
@ -100,3 +100,11 @@ M: unix-io file-info ( path -- info )
|
||||||
|
|
||||||
M: unix-io link-info ( path -- info )
|
M: unix-io link-info ( path -- info )
|
||||||
normalize-pathname lstat* stat>file-info ;
|
normalize-pathname lstat* stat>file-info ;
|
||||||
|
|
||||||
|
M: unix-io make-link ( path1 path2 -- )
|
||||||
|
normalize-pathname symlink io-error ;
|
||||||
|
|
||||||
|
M: unix-io read-link ( path -- path' )
|
||||||
|
normalize-pathname
|
||||||
|
PATH_MAX [ <byte-array> tuck ] [ ] bi readlink
|
||||||
|
dup io-error head-slice >string ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: alien.c-types io io.files io.nonblocking kernel
|
USING: alien.c-types io io.files io.nonblocking kernel
|
||||||
namespaces random io.encodings.binary singleton init
|
namespaces random io.encodings.binary singleton init
|
||||||
accessors ;
|
accessors system ;
|
||||||
IN: random.unix
|
IN: random.unix
|
||||||
|
|
||||||
TUPLE: unix-random path ;
|
TUPLE: unix-random path ;
|
||||||
|
@ -15,7 +15,14 @@ C: <unix-random> unix-random
|
||||||
M: unix-random random-bytes* ( n tuple -- byte-array )
|
M: unix-random random-bytes* ( n tuple -- byte-array )
|
||||||
path>> file-read-unbuffered ;
|
path>> file-read-unbuffered ;
|
||||||
|
|
||||||
[
|
os "openbsd" = [
|
||||||
"/dev/random" <unix-random> secure-random-generator set-global
|
[
|
||||||
"/dev/urandom" <unix-random> insecure-random-generator set-global
|
"/dev/srandom" <unix-random> secure-random-generator set-global
|
||||||
] "random.unix" add-init-hook
|
"/dev/prandom" <unix-random> insecure-random-generator set-global
|
||||||
|
] "random.unix" add-init-hook
|
||||||
|
] [
|
||||||
|
[
|
||||||
|
"/dev/random" <unix-random> secure-random-generator set-global
|
||||||
|
"/dev/urandom" <unix-random> insecure-random-generator set-global
|
||||||
|
] "random.unix" add-init-hook
|
||||||
|
] if
|
||||||
|
|
|
@ -77,6 +77,7 @@ FUNCTION: int pclose ( void* file ) ;
|
||||||
FUNCTION: int pipe ( int* filedes ) ;
|
FUNCTION: int pipe ( int* filedes ) ;
|
||||||
FUNCTION: void* popen ( char* command, char* type ) ;
|
FUNCTION: void* popen ( char* command, char* type ) ;
|
||||||
FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ;
|
FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ;
|
||||||
|
FUNCTION: ssize_t readlink ( char* path, char* buf, size_t bufsize ) ;
|
||||||
FUNCTION: ssize_t recv ( int s, void* buf, size_t nbytes, int flags ) ;
|
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: 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 rename ( char* from, char* to ) ;
|
||||||
|
@ -93,6 +94,7 @@ FUNCTION: int setsockopt ( int s, int level, int optname, void* optval, socklen_
|
||||||
FUNCTION: int setuid ( uid_t uid ) ;
|
FUNCTION: int setuid ( uid_t uid ) ;
|
||||||
FUNCTION: int socket ( int domain, int type, int protocol ) ;
|
FUNCTION: int socket ( int domain, int type, int protocol ) ;
|
||||||
FUNCTION: char* strerror ( int errno ) ;
|
FUNCTION: char* strerror ( int errno ) ;
|
||||||
|
FUNCTION: int symlink ( char* path1, char* path2 ) ;
|
||||||
FUNCTION: int system ( char* command ) ;
|
FUNCTION: int system ( char* command ) ;
|
||||||
FUNCTION: int unlink ( char* path ) ;
|
FUNCTION: int unlink ( char* path ) ;
|
||||||
FUNCTION: int utimes ( char* path, timeval[2] times ) ;
|
FUNCTION: int utimes ( char* path, timeval[2] times ) ;
|
||||||
|
@ -102,6 +104,8 @@ FUNCTION: int utimes ( char* path, timeval[2] times ) ;
|
||||||
|
|
||||||
FUNCTION: int kill ( pid_t pid, int sig ) ;
|
FUNCTION: int kill ( pid_t pid, int sig ) ;
|
||||||
|
|
||||||
|
: PATH_MAX 1024 ; inline
|
||||||
|
|
||||||
: PRIO_PROCESS 0 ; inline
|
: PRIO_PROCESS 0 ; inline
|
||||||
: PRIO_PGRP 1 ; inline
|
: PRIO_PGRP 1 ; inline
|
||||||
: PRIO_USER 2 ; inline
|
: PRIO_USER 2 ; inline
|
||||||
|
|
Loading…
Reference in New Issue