diff options
| author | Graydon Hoare <[email protected]> | 2010-08-18 15:40:27 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-18 15:41:24 -0700 |
| commit | f0d4e6c5119b377b6f3744aa77263a65136eb63b (patch) | |
| tree | 5feefac9a0abf3ad73e9edc05b7ca6da9d9a1b4f | |
| parent | Don't complain about \r when core.autocrlf is on in Git (now working with Pyt... (diff) | |
| download | rust-f0d4e6c5119b377b6f3744aa77263a65136eb63b.tar.xz rust-f0d4e6c5119b377b6f3744aa77263a65136eb63b.zip | |
Add stdio_reader to io, just use FILE* values for now. We have things to do.
| -rw-r--r-- | src/lib/_io.rs | 32 | ||||
| -rw-r--r-- | src/lib/linux_os.rs | 5 | ||||
| -rw-r--r-- | src/lib/macos_os.rs | 5 | ||||
| -rw-r--r-- | src/lib/win32_os.rs | 5 |
4 files changed, 46 insertions, 1 deletions
diff --git a/src/lib/_io.rs b/src/lib/_io.rs index 93d06d41..a7feba2f 100644 --- a/src/lib/_io.rs +++ b/src/lib/_io.rs @@ -1,7 +1,26 @@ -import std.os; +import std.os.libc; import std._str; import std._vec; + +type stdio_reader = unsafe obj { + fn getc() -> int; +}; + +fn new_stdio_reader(str path) -> stdio_reader { + unsafe obj stdio_FILE_reader(os.libc.FILE f) { + fn getc() -> int { + ret os.libc.fgetc(f); + } + drop { + os.libc.fclose(f); + } + } + ret stdio_FILE_reader(os.libc.fopen(_str.buf(path), + _str.buf("r"))); +} + + type buf_reader = unsafe obj { fn read() -> vec[u8]; }; @@ -130,3 +149,14 @@ fn file_writer(str path, } ret fw(new_buf_writer(path, flags)); } + +// +// Local Variables: +// mode: rust +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: +// diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs index 3f096e99..2ff61dc3 100644 --- a/src/lib/linux_os.rs +++ b/src/lib/linux_os.rs @@ -8,6 +8,11 @@ native mod libc = "libc.so.6" { fn write(int fd, vbuf buf, uint count) -> int; fn close(int fd) -> int; + type FILE; + fn fopen(sbuf path, sbuf mode) -> FILE; + fn fclose(FILE f); + fn fgetc(FILE f) -> int; + type dir; // readdir is a mess; handle via wrapper function in rustrt. fn opendir(sbuf d) -> dir; diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs index 2ada5c07..6f561306 100644 --- a/src/lib/macos_os.rs +++ b/src/lib/macos_os.rs @@ -8,6 +8,11 @@ native mod libc = "libc.dylib" { fn write(int fd, vbuf buf, uint count) -> int; fn close(int fd) -> int; + type FILE; + fn fopen(sbuf path, sbuf mode) -> FILE; + fn fclose(FILE f); + fn fgetc(FILE f) -> int; + type dir; // readdir is a mess; handle via wrapper function in rustrt. fn opendir(sbuf d) -> dir; diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index 3d8e5f3a..3e1ce65f 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -6,6 +6,11 @@ native mod libc = "msvcrt.dll" { fn read(int fd, vbuf buf, uint count) -> int = "_read"; fn write(int fd, vbuf buf, uint count) -> int = "_write"; fn close(int fd) -> int = "_close"; + + type FILE; + fn fopen(sbuf path, sbuf mode) -> FILE; + fn fclose(FILE f); + fn fgetc(FILE f) -> int; } mod libc_constants { |