Skip to content

Commit c31b8cc

Browse files
committed
Implement OS.chDir
* Fixes #248.
1 parent 3739933 commit c31b8cc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

vm/boostenv/lib/OS.oz

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ export
4646
GetEnv
4747
PutEnv
4848

49-
% File I/0
49+
% Directories
5050
GetDir
5151
GetCWD
52+
ChDir
5253
Tmpnam
5354

55+
% File I/0
5456
Fopen
5557
Fread
5658
Fwrite
@@ -136,6 +138,7 @@ define
136138
end
137139

138140
GetCWD = Boot_OS.getCWD
141+
ChDir = Boot_OS.chDir
139142
Tmpnam = Boot_OS.tmpnam
140143

141144
fun {Fopen FileName Mode}

vm/boostenv/main/modos.hh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,24 @@ public:
280280
}
281281
};
282282

283+
class ChDir: public Builtin<ChDir> {
284+
public:
285+
ChDir(): Builtin("chDir") {}
286+
287+
static void call(VM vm, In dir) {
288+
size_t dirBufSize = ozVSLengthForBuffer(vm, dir);
289+
std::string dirStr;
290+
291+
ozVSGet(vm, dir, dirBufSize, dirStr);
292+
293+
boost::system::error_code ec;
294+
boost::filesystem::current_path(dirStr, ec);
295+
if (ec) {
296+
raiseOSError(vm, "chdir", ec);
297+
}
298+
}
299+
};
300+
283301
class Tmpnam: public Builtin<Tmpnam> {
284302
public:
285303
Tmpnam(): Builtin("tmpnam") {}

0 commit comments

Comments
 (0)