-
Notifications
You must be signed in to change notification settings - Fork 54
/
posix.read.m
60 lines (48 loc) · 1.91 KB
/
posix.read.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
55
56
57
58
59
60
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 1999, 2007 The University of Melbourne.
% Copyright (C) 2018-2019 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%-----------------------------------------------------------------------------%
%
% Module: posix.read.
% Main author: conway@cs.mu.oz.au
%
%-----------------------------------------------------------------------------%
:- module posix.read.
:- interface.
:- import_module bitmap.
:- pred read(fd::in, int::in, posix.result(int)::out,
bitmap::bitmap_di, bitmap::bitmap_uo, io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- pragma foreign_decl("C", "
#include <unistd.h>
").
%-----------------------------------------------------------------------------%
read(Fd, ToRead, Result, !Bitmap, !IO) :-
read0(Fd, ToRead, Read, !Bitmap, !IO),
( if Read < 0 then
errno(Err, !IO),
Result = error(Err)
else
Result = ok(Read)
).
:- pred read0(fd::in, int::in, int::out,
bitmap::bitmap_di, bitmap::bitmap_uo, io::di, io::uo) is det.
:- pragma foreign_proc("C",
read0(Fd::in, ToRead::in, Read::out, Bitmap0::bitmap_di, Bitmap::bitmap_uo,
_IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
"
do {
Read = read(Fd, Bitmap0->elements, ToRead);
} while (Read == -1 && MR_is_eintr(errno));
Bitmap = Bitmap0;
").
%-----------------------------------------------------------------------------%
:- end_module posix.read.
%-----------------------------------------------------------------------------%