diff options
| author | Marijn Haverbeke <[email protected]> | 2011-03-04 07:22:43 +0100 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-07 12:58:08 -0800 |
| commit | 0624f9db4aeaa5681941750c3a1a17ca5fbb7e72 (patch) | |
| tree | 91844d79c0c5614ce660c3c20f1c67eaef2d5021 /src/lib | |
| parent | Construct the wrappers to native functions. Hello world now works :-) (diff) | |
| download | rust-0624f9db4aeaa5681941750c3a1a17ca5fbb7e72.tar.xz rust-0624f9db4aeaa5681941750c3a1a17ca5fbb7e72.zip | |
Add a pretty-printer
Adds a -pp option to the compiler which will cause it to simply
pretty-print the given file.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/io.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/lib/io.rs b/src/lib/io.rs index 9f428cee..0c4eb39e 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -91,24 +91,28 @@ tag fileflag { truncate; } +fn writefd(int fd, vec[u8] v) { + auto len = _vec.len[u8](v); + auto count = 0u; + auto vbuf; + while (count < len) { + vbuf = _vec.buf_off[u8](v, count); + auto nout = os.libc.write(fd, vbuf, len); + if (nout < 0) { + log "error dumping buffer"; + log sys.rustrt.last_os_error(); + fail; + } + count += nout as uint; + } +} + fn new_buf_writer(str path, vec[fileflag] flags) -> buf_writer { state obj fd_buf_writer(int fd) { fn write(vec[u8] v) { - auto len = _vec.len[u8](v); - auto count = 0u; - auto vbuf; - while (count < len) { - vbuf = _vec.buf_off[u8](v, count); - auto nout = os.libc.write(fd, vbuf, len); - if (nout < 0) { - log "error dumping buffer"; - log sys.rustrt.last_os_error(); - fail; - } - count += nout as uint; - } + writefd(fd, v); } drop { |