-
Notifications
You must be signed in to change notification settings - Fork 54
/
errno.m
54 lines (41 loc) · 1.67 KB
/
errno.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
50
51
52
53
54
%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2014, 2018 The Mercury Team.
% This file is distributed under the terms specified in COPYING.LIB.
%---------------------------------------------------------------------------%
%
% Module: errno.
% Main Author: Paul Bone <paul@bone.id.au>
% Stability: low
%
% Provide an interface to the C errno type and functions.
%
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- module net.errno.
:- interface.
:- import_module int.
:- import_module string.
:- type errno == int.
:- func strerror(errno) = string.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- pragma foreign_decl("C", "#include \"mercury_runtime_util.h\"").
%---------------------------------------------------------------------------%
% Errno handling.
%
strerror(Errno) = String :-
strerror(Errno, String).
:- pred strerror(int::in, string::uo) is det.
:- pragma foreign_proc("C",
strerror(Errno::in, Str::uo),
[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
"
char errbuf[MR_STRERROR_BUF_SIZE];
MR_make_aligned_string_copy(Str,
MR_strerror(Errno, errbuf, sizeof(errbuf)));
").
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%