-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
{ 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
! 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 ;