-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathposix.chdir.m
49 lines (40 loc) · 1.53 KB
/
posix.chdir.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%----------------------------------------------------------------------------%
% Copyright (C) 2020 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%----------------------------------------------------------------------------%
%
% Module: posix.chdir.m
% Main author: Volker Wysk <[email protected]>
%
%----------------------------------------------------------------------------%
:- module posix.chdir.
:- interface.
:- import_module io.
:- import_module string.
% Change the working directory. See chdir(2).
%
:- pred chdir(string::in, posix.result::out, io::di, io::uo) is det.
%----------------------------------------------------------------------------%
%----------------------------------------------------------------------------%
:- implementation.
chdir(Path, Res, !IO) :-
chdir0(Path, Res0, !IO),
( if Res0 \= 0 then
errno(Errno, !IO),
Res = error(Errno)
else
Res = ok
).
:- pragma foreign_decl("C", "#include <unistd.h>").
:- pred chdir0(string::in, int::out, io::di, io::uo) is det.
:- pragma foreign_proc("C",
chdir0(Path::in, Res0::out, _IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
"
Res0 = chdir(Path);
").
%----------------------------------------------------------------------------%
:- end_module posix.chdir.
%----------------------------------------------------------------------------%