summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-04-20 00:32:43 -0400
committerJune McEnroe <june@causal.agency>2018-04-20 00:32:43 -0400
commit0ecf4bf4cb26fb7de9ff69b437349aeddedb92b4 (patch)
tree32d56366126ba0bc2c0ade6154ee8a5490268048
parentRemove winch (diff)
downloadstream-0ecf4bf4cb26fb7de9ff69b437349aeddedb92b4.tar.gz
stream-0ecf4bf4cb26fb7de9ff69b437349aeddedb92b4.zip
Uncommitted changes from months ago :(
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--create.c4
-rw-r--r--destroy.c2
-rw-r--r--ingest.c46
4 files changed, 20 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index e37fc70..7e8053e 100644
--- a/Makefile
+++ b/Makefile
@@ -34,5 +34,3 @@ chroot.tar: $(BINS)
 
 clean:
 	rm -f tags $(BINS) chroot.tar
-
-.PHONY: all clean
diff --git a/create.c b/create.c
index 49cadb6..59eb3e0 100644
--- a/create.c
+++ b/create.c
@@ -26,8 +26,8 @@ int main(int argc, char *argv[]) {
     if (argc < 2) errx(EX_USAGE, "missing public id");
 
     uint32_t id[4];
-    char public[10 + 32 + 1];
-    char private[8 + 32 + 1];
+    char public[sizeof("../public/") + 32];
+    char private[sizeof("private/") + 2 * sizeof(id)];
 
     arc4random_buf(id, sizeof(id));
     snprintf(public, sizeof(public), "public/%s", argv[1]);
diff --git a/destroy.c b/destroy.c
index 02355f0..6a82bbe 100644
--- a/destroy.c
+++ b/destroy.c
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
     if (fd < 0) err(EX_NOINPUT, "private");
 
     const char *private = argv[1];
-    char public[10 + 32 + 1] = {0};
+    char public[sizeof("../public/") + 32] = {0};
     ssize_t n = readlinkat(fd, private, public, sizeof(public) - 1);
     if (n < 0) err(EX_NOINPUT, "%s", private);
 
diff --git a/ingest.c b/ingest.c
index dfc480c..b729169 100644
--- a/ingest.c
+++ b/ingest.c
@@ -20,47 +20,35 @@
 #include <sysexits.h>
 #include <unistd.h>
 
-static struct {
-    int local;
-    int remote;
-} fd = { -1, STDIN_FILENO };
-
 int main(int argc, char *argv[]) {
     if (argc < 2) errx(EX_USAGE, "missing private id");
 
     const char *path = argv[1];
-    fd.local = open(path, O_WRONLY);
-    if (fd.local < 0) err(EX_NOINPUT, "%s", path);
+    int local = open(path, O_WRONLY);
+    if (local < 0) err(EX_NOINPUT, "%s", path);
+
+    int remote = STDIN_FILENO;
 
     struct winsize window;
-    ssize_t size = read(fd.remote, &window, sizeof(window));
-    if (size < 0) err(EX_IOERR, "read(%d)", fd.remote);
-    if ((size_t)size < sizeof(window)) errx(EX_IOERR, "short read(%d)", fd.remote);
+    ssize_t size = read(remote, &window, sizeof(window));
+    if (size < 0) err(EX_IOERR, "read(%d)", remote);
+    if ((size_t)size < sizeof(window)) errx(EX_DATAERR, "short read(%d)", remote);
 
     for (;;) {
-        int error = ftruncate(fd.local, 0);
-        if (error) err(EX_IOERR, "%s", path);
+        ftruncate(local, 0);
+        lseek(local, 0, SEEK_SET);
 
-        off_t off = lseek(fd.local, 0, SEEK_SET);
-        if (off < 0) err(EX_IOERR, "%s", path);
-
-        ssize_t size = write(fd.local, &window, sizeof(window));
-        if (size < 0) err(EX_IOERR, "write(%d)", fd.local);
-        if ((size_t)size < sizeof(window)) {
-            errx(EX_IOERR, "short write(%d)", fd.local);
-        }
+        ssize_t size = write(local, &window, sizeof(window));
+        if (size < 0) err(EX_IOERR, "write(%d)", local);
 
         char buf[4096];
-        for (ssize_t totalSize = 0; totalSize < 1024 * 1024;) {
-            ssize_t readSize = read(fd.remote, buf, sizeof(buf));
-            if (readSize < 0) err(EX_IOERR, "read(%d)", fd.remote);
-            if (!readSize) return EX_OK;
-
-            ssize_t writeSize = write(fd.local, buf, readSize);
-            if (writeSize < 0) err(EX_IOERR, "write(%d)", fd.local);
-            if (writeSize < readSize) errx(EX_IOERR, "short write(%d)", fd.local);
+        for (size_t totalSize = 0; totalSize < 1024 * 1024; totalSize += size) {
+            size = read(remote, buf, sizeof(buf));
+            if (size < 0) err(EX_IOERR, "read(%d)", remote);
+            if (!size) return EX_OK;
 
-            totalSize += readSize;
+            size = write(local, buf, size);
+            if (size < 0) err(EX_IOERR, "write(%d)", local);
         }
     }
 }