lib/standard/file: Added a way to change the buffering for a specified stream
[nit.git] / src / interpreter / primitive_types.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Encapsulates all primitive data types of nit
12 #
13 # Ensures that the use in the interpreter is independant of the
14 # underlying implementation and that the services are semantically correct.
15 module primitive_types
16
17 intrude import standard::file
18
19 # Wrapper for `NativeFile`
20 class PrimitiveNativeFile
21
22 var file: FStream
23
24 init native_stdin do
25 file = new IFStream.from_fd(0)
26 end
27
28 init native_stdout do
29 file = new OFStream.from_fd(1)
30 end
31
32 init native_stderr do
33 file = new OFStream.from_fd(2)
34 end
35
36 init io_open_read(path: String) do
37 file = new IFStream.open(path.to_s)
38 end
39
40 init io_open_write(path: String) do
41 file = new OFStream.open(path.to_s)
42 end
43
44 fun address_is_null: Bool do return file._file.address_is_null
45
46 fun io_read(buf: NativeString, len: Int): Int do return file._file.io_read(buf, len)
47
48 fun io_write(buf: NativeString, len: Int): Int do return file._file.io_write(buf, len)
49
50 fun io_close: Int do return file._file.io_close
51
52 fun file_stat: FileStat do return file._file.file_stat
53
54 fun fileno: Int do return file._file.fileno
55
56 fun flush: Int do return file._file.flush
57
58 fun set_buffering_type(size, mode: Int): Int do
59 return file._file.set_buffering_type(size, mode)
60 end
61 end