aboutsummaryrefslogtreecommitdiff
path: root/src/lib/_io.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-06-23 21:03:09 -0700
committerGraydon Hoare <[email protected]>2010-06-23 21:03:09 -0700
commitd6b7c96c3eb29b9244ece0c046d3f372ff432d04 (patch)
treeb425187e232966063ffc2f0d14c04a55d8f004ef /src/lib/_io.rs
parentInitial git commit. (diff)
downloadrust-d6b7c96c3eb29b9244ece0c046d3f372ff432d04.tar.xz
rust-d6b7c96c3eb29b9244ece0c046d3f372ff432d04.zip
Populate tree.
Diffstat (limited to 'src/lib/_io.rs')
-rw-r--r--src/lib/_io.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/_io.rs b/src/lib/_io.rs
new file mode 100644
index 00000000..1f01c3b3
--- /dev/null
+++ b/src/lib/_io.rs
@@ -0,0 +1,36 @@
+type buf_reader = obj {
+ fn read(vec[u8] buf) -> uint;
+};
+
+type buf_writer = obj {
+ fn write(vec[u8] buf) -> uint;
+};
+
+fn mk_buf_reader(str s) -> buf_reader {
+
+ obj fd_reader(int fd) {
+ fn read(vec[u8] v) -> uint {
+ auto len = _vec.len[u8](v);
+ auto buf = _vec.buf[u8](v);
+ auto count = os.libc.read(fd, buf, len);
+ if (count < 0) {
+ log "error filling buffer";
+ log sys.rustrt.last_os_error();
+ fail;
+ } else {
+ ret uint(count);
+ }
+ }
+ drop {
+ os.libc.close(fd);
+ }
+ }
+
+ auto fd = os.libc.open(_str.buf(s), 0);
+ if (fd < 0) {
+ log "error opening file";
+ log sys.rustrt.last_os_error();
+ fail;
+ }
+ ret fd_reader(fd);
+}