[strongtalk] r196 committed - Allow access to currentDirectory under Unix and OSX

2 views
Skip to first unread message

codesite...@google.com

unread,
Dec 31, 2009, 2:05:04 PM12/31/09
to strongta...@googlegroups.com
Revision: 196
Author: StephenLRees
Date: Thu Dec 31 10:59:55 2009
Log: Allow access to currentDirectory under Unix and OSX
http://code.google.com/p/strongtalk/source/detail?r=196

Modified:
/branches/gcc-linux/StrongtalkSource/MacOSXFilePath.dlt
/branches/gcc-linux/StrongtalkSource/UnixFilePath.dlt

=======================================
--- /branches/gcc-linux/StrongtalkSource/MacOSXFilePath.dlt Sun Aug 9
17:16:11 2009
+++ /branches/gcc-linux/StrongtalkSource/MacOSXFilePath.dlt Thu Dec 31
10:59:55 2009
@@ -9,6 +9,13 @@
comment:
''!

+! (Delta mirrorFor: #MacOSXFilePath) classSide methodsFor: 'private' !
+
+
+libcName
+
+ ^'libc.dylib'! !
+
! (Delta mirrorFor: #MacOSXFilePath) methodsFor: 'private' !


=======================================
--- /branches/gcc-linux/StrongtalkSource/UnixFilePath.dlt Mon Dec 28
10:40:02 2009
+++ /branches/gcc-linux/StrongtalkSource/UnixFilePath.dlt Thu Dec 31
10:59:55 2009
@@ -15,21 +15,24 @@

currentDirectory ^<FilePath>

- | buf <CString> buflen <Int> |
+ | buf <CString> buflen <Int> getcwd <Alien> |
buflen := 1000.
- buf := CString new malloc: buflen.
- ^[ {{<kernel ExternalProxy GetCurrentDirectoryA>
- size: buflen
- buf: buf
- }} isNull
- ifTrue: [ Win32 handleError ]
- ifFalse: [ self new pattern: buf asString ]
+ buf := Alien newC: buflen.
+ getcwd := Alien lookup: 'getcwd' inLibrary: self libcName.
+ ^[|result|
+ getcwd
+ primFFICallResult: (result := Alien new: 4)
+ with: buf pointer
+ with: buflen.
+ result asUnsignedLong = 0
+ ifTrue: [self error: 'Unable to get current directory']
+ ifFalse: [self new pattern: buf asString ]
] ensure: [ buf free ]!

currentDirectory: file <FilePath>

| result <Alien> name <Alien> chdir <Alien> |
- chdir := Alien lookup: 'chdir' inLibrary: 'libc.so.6'.
+ chdir := Alien lookup: 'chdir' inLibrary: self libcName.
result := Alien new: 4.
name := file name asString asAlien.
[chdir
@@ -37,7 +40,11 @@
with: name pointer.
result asSignedLong = 0 ifFalse: [self error: 'Unable to cd to
directory ', file name]]
ensure: [name free]
- ! !
+ !
+
+libcName
+
+ ^'libc.so.6'! !

! (Delta mirrorFor: #UnixFilePath) methodsFor: 'accessing' !

Reply all
Reply to author
Forward
0 new messages