aboutsummaryrefslogtreecommitdiff
path: root/src/lib/io.rs
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-03-11 13:30:18 +0100
committerGraydon Hoare <[email protected]>2011-03-14 14:57:13 -0700
commitea5dc54c3f0444fd3f20191fa1b1d94372c74c65 (patch)
tree0a80b98563553f56962cc956e94210462a9d66e2 /src/lib/io.rs
parentExtend stream functionality (diff)
downloadrust-ea5dc54c3f0444fd3f20191fa1b1d94372c74c65.tar.xz
rust-ea5dc54c3f0444fd3f20191fa1b1d94372c74c65.zip
Add functionality for running external programs to the std lib
See lib/run_program.rs.
Diffstat (limited to 'src/lib/io.rs')
-rw-r--r--src/lib/io.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/lib/io.rs b/src/lib/io.rs
index 45bdb4a0..7135c2bc 100644
--- a/src/lib/io.rs
+++ b/src/lib/io.rs
@@ -17,6 +17,8 @@ type reader =
impure fn read_bytes(uint len) -> vec[u8];
impure fn read_char() -> int;
impure fn unread_char(int i);
+ impure fn eof() -> bool;
+ impure fn read_line() -> str;
impure fn read_c_str() -> str;
impure fn read_le_uint(uint size) -> uint;
impure fn read_le_int(uint size) -> int;
@@ -31,7 +33,7 @@ state obj FILE_reader(os.libc.FILE f, bool must_close) {
impure fn read_bytes(uint len) -> vec[u8] {
auto buf = _vec.alloc[u8](len);
auto read = os.libc.fread(_vec.buf[u8](buf), 1u, len, f);
- check(read == len);
+ _vec.len_set[u8](buf, read);
ret buf;
}
impure fn read_char() -> int {
@@ -40,6 +42,21 @@ state obj FILE_reader(os.libc.FILE f, bool must_close) {
impure fn unread_char(int ch) {
os.libc.ungetc(ch, f);
}
+ impure fn eof() -> bool {
+ auto ch = os.libc.fgetc(f);
+ if (ch == -1) {ret true;}
+ os.libc.ungetc(ch, f);
+ ret false;
+ }
+ impure fn read_line() -> str {
+ auto buf = "";
+ while (true) {
+ auto ch = os.libc.fgetc(f);
+ if (ch == -1) {break;} if (ch == 10) {break;}
+ buf += _str.unsafe_from_bytes(vec(ch as u8));
+ }
+ ret buf;
+ }
impure fn read_c_str() -> str {
auto buf = "";
while (true) {