Skip to content

Commit a6c42d0

Browse files
committed
---
yaml --- r: 557 b: refs/heads/master c: 2da4fec h: refs/heads/master i: 555: 6d6d5b2 v: v3
1 parent 359e64d commit a6c42d0

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: af64e4f30536e55c6fc11a19eaad99cd06b0f4b6
2+
refs/heads/master: 2da4fecacd1b61e9e090e93c33394712fa7f066c

trunk/src/lib/_io.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,18 @@ fn new_buf_reader(str path) -> buf_reader {
8484
ret fd_buf_reader(fd, new_buf());
8585
}
8686

87-
type fileflag = tag(append(), create(), truncate());
87+
/**
88+
* FIXME (issue #150): This should be
89+
*
90+
* type fileflag = tag(append(), create(), truncate());
91+
*
92+
* but then the tag value ctors are not found from crate-importers of std, so
93+
* we manually simulate the enum below.
94+
*/
95+
type fileflag = uint;
96+
fn append() -> uint { ret 0u; }
97+
fn create() -> uint { ret 1u; }
98+
fn truncate() -> uint { ret 2u; }
8899

89100
fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
90101

@@ -117,9 +128,13 @@ fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
117128

118129
for (fileflag f in flags) {
119130
alt (f) {
120-
case (append()) { fflags |= os.libc_constants.O_APPEND(); }
121-
case (create()) { fflags |= os.libc_constants.O_CREAT(); }
122-
case (truncate()) { fflags |= os.libc_constants.O_TRUNC(); }
131+
// FIXME (issue #150): cf comment above defn of fileflag type
132+
//case (append()) { fflags |= os.libc_constants.O_APPEND(); }
133+
//case (create()) { fflags |= os.libc_constants.O_CREAT(); }
134+
//case (truncate()) { fflags |= os.libc_constants.O_TRUNC(); }
135+
case (0u) { fflags |= os.libc_constants.O_APPEND(); }
136+
case (1u) { fflags |= os.libc_constants.O_CREAT(); }
137+
case (2u) { fflags |= os.libc_constants.O_TRUNC(); }
123138
}
124139
}
125140

trunk/src/lib/_str.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ native "rust" mod rustrt {
1111
fn refcount[T](str s) -> uint;
1212
}
1313

14+
fn eq(str a, str b) -> bool {
15+
let uint i = byte_len(a);
16+
if (byte_len(b) != i) {
17+
ret false;
18+
}
19+
while (i > 0u) {
20+
i -= 1u;
21+
auto cha = a.(i);
22+
auto chb = b.(i);
23+
if (cha != chb) {
24+
ret false;
25+
}
26+
}
27+
ret true;
28+
}
29+
1430
fn is_utf8(vec[u8] v) -> bool {
1531
fail; // FIXME
1632
}

trunk/src/test/run-pass/lib-io.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// -*- rust -*-
2+
3+
use std;
4+
import std._io;
5+
import std._str;
6+
7+
fn test_simple(str tmpfilebase) {
8+
let str tmpfile = tmpfilebase + ".tmp";
9+
log tmpfile;
10+
let str frood = "A hoopy frood who really knows where his towel is.";
11+
log frood;
12+
13+
{
14+
let _io.buf_writer out = _io.new_buf_writer(tmpfile, vec(_io.create()));
15+
out.write(_str.bytes(frood));
16+
}
17+
18+
let _io.buf_reader inp = _io.new_buf_reader(tmpfile);
19+
let str frood2 = _str.from_bytes(inp.read());
20+
log frood2;
21+
check (_str.eq(frood, frood2));
22+
}
23+
24+
fn main(vec[str] argv) {
25+
test_simple(argv.(0));
26+
}

0 commit comments

Comments
 (0)