io.files.unix: loop getcwd with an expanding buffer, fixes part of #1074
It appears that the right way to do it is using an arbitrary sized buffer and just expanding it in case getcwd reports ERANGE.locals-and-roots
parent
83e1ee5084
commit
53467d4e21
|
|
@ -1,8 +1,7 @@
|
|||
USING: tools.test io.files io.files.temp io.pathnames
|
||||
io.directories io.files.info io.files.info.unix continuations
|
||||
kernel io.files.unix math.bitwise calendar accessors
|
||||
math.functions math unix.users unix.groups arrays sequences
|
||||
grouping io.pathnames.private literals ;
|
||||
USING: accessors arrays calendar continuations grouping io.directories
|
||||
io.files.info io.files.info.unix io.files.temp io.files.unix
|
||||
io.pathnames kernel literals math math.bitwise math.functions
|
||||
sequences strings tools.test unix.groups unix.users ;
|
||||
IN: io.files.unix.tests
|
||||
|
||||
{ "/usr/libexec/" } [ "/usr/libexec/awk/" parent-directory ] unit-test
|
||||
|
|
@ -163,3 +162,8 @@ prepare-test-file
|
|||
{ f } [ 0 other-read? ] unit-test
|
||||
{ f } [ 0 other-write? ] unit-test
|
||||
{ f } [ 0 other-execute? ] unit-test
|
||||
|
||||
! (cwd)
|
||||
{ t } [
|
||||
1 (cwd) string?
|
||||
] unit-test
|
||||
|
|
|
|||
|
|
@ -1,14 +1,21 @@
|
|||
! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: byte-arrays destructors environment io.backend.unix
|
||||
io.files io.files.private io.pathnames io.ports kernel libc
|
||||
literals system unix unix.ffi ;
|
||||
USING: accessors byte-arrays continuations destructors environment
|
||||
io.backend.unix io.files io.files.private io.pathnames io.ports kernel
|
||||
libc literals math system unix unix.ffi ;
|
||||
IN: io.files.unix
|
||||
|
||||
: (cwd) ( bufsiz -- path )
|
||||
[
|
||||
dup <byte-array> over [ getcwd ] unix-system-call nip
|
||||
] [
|
||||
dup errno>> ERANGE = [
|
||||
drop 2 * (cwd)
|
||||
] [ rethrow ] if
|
||||
] recover ;
|
||||
|
||||
M: unix cwd ( -- path )
|
||||
MAXPATHLEN [ <byte-array> ] keep
|
||||
[ getcwd ] unix-system-call
|
||||
[ throw-errno ] unless* ;
|
||||
4096 (cwd) ;
|
||||
|
||||
M: unix cd ( path -- ) [ chdir ] unix-system-call drop ;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue