summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@exolobe1>2018-05-12 08:12:53 +0000
committerLars Wirzenius <liw@exolobe1>2018-05-12 08:12:53 +0000
commit4a077a88b3c8290935e05283caa861e253278582 (patch)
tree27e85d024cda5a8bc120060685b64242163a3a65
downloadcat-4a077a88b3c8290935e05283caa861e253278582.tar.gz
Add: initial commit
-rw-r--r--.gitignore3
-rw-r--r--Cargo.toml6
-rw-r--r--src/main.rs37
-rw-r--r--zerosbin0 -> 12765 bytes
4 files changed, 46 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..70e3cae
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+
+/target
+**/*.rs.bk
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..3eb3e52
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "cat"
+version = "0.1.0"
+authors = ["liw"]
+
+[dependencies]
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..b2ee6f0
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,37 @@
+use std::env;
+use std::fs::File;
+use std::io;
+use std::io::prelude::*;
+
+const BUFSIZE: usize = 17;
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ for arg in &args[1..] {
+ cat(arg, BUFSIZE);
+ }
+}
+
+
+fn cat(filename: &str, bufsize: usize) {
+ // The following gives fugly error message if there's a problem.
+ // Need to find a better way to report errors to normal people.
+ let mut f = File::open(filename).unwrap();
+
+ let mut buffer = vec![0; bufsize];
+ loop {
+ match f.read(&mut buffer).unwrap() {
+ 0 => break,
+ n => write(&buffer[..n]),
+ };
+ }
+}
+
+
+fn write(buffer: &[u8]) {
+ // Again, the error message is fugly if there's a problem. Also,
+ // ideally this wouldn't hardcode the output stream, but it turns
+ // out that io::stdout() doesn't return a File, so passing in an
+ // open file is tricky.
+ io::stdout().write(&buffer).unwrap();
+}
diff --git a/zeros b/zeros
new file mode 100644
index 0000000..eec1b74
--- /dev/null
+++ b/zeros
Binary files differ