]> git.scottworley.com Git - overonion/blobdiff - reverse_lib.c
Whitespace: Single-line error checks
[overonion] / reverse_lib.c
index e69922b181d3adc76153c311889d74822bd85ac7..45c45955424a1a7f22f76acb19ed297a8cbf29fb 100644 (file)
@@ -15,31 +15,23 @@ static void write_all(int fd, const void *buf, size_t count) {
   size_t written = 0;
   while (written < count) {
     int ret = write(fd, &cbuf[written], count - written);
-    if (ret == -1) {
-      err(EX_IOERR, "Could not write");
-    }
+    if (ret == -1) err(EX_IOERR, "Could not write");
     written += ret;
   }
 }
 
 void reverse_file(const char* input_filename, int output_fd) {
   int fd = open(input_filename, O_RDONLY);
-  if (fd == -1) {
-    err(EX_NOINPUT, "Could not open specified file");
-  }
+  if (fd == -1) err(EX_NOINPUT, "Could not open specified file");
 
   struct stat stats;
-  if (fstat(fd, &stats) == -1) {
-    err(EX_NOINPUT, "Could not stat input");
-  }
+  if (fstat(fd, &stats) == -1) err(EX_NOINPUT, "Could not stat input");
 
   long page_size = sysconf(_SC_PAGE_SIZE);
   off_t pages = (stats.st_size - 1) / page_size + 1;
   long map_size = pages * page_size;
   char *m = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fd, 0);
-  if (m == MAP_FAILED) {
-    err(EX_NOINPUT, "Could not mmap input");
-  }
+  if (m == MAP_FAILED) err(EX_NOINPUT, "Could not mmap input");
 
   char buf[BUFFER_SIZE];
   off_t buf_offset = 0;
@@ -54,10 +46,6 @@ void reverse_file(const char* input_filename, int output_fd) {
     write_all(output_fd, buf, buf_offset);
   }
 
-  if (munmap(m, map_size) == -1) {
-    err(EX_IOERR, "Could not unmap input");
-  }
-  if (close(fd) == -1) {
-    err(EX_IOERR, "Could not close input");
-  }
+  if (munmap(m, map_size) == -1) err(EX_IOERR, "Could not unmap input");
+  if (close(fd) == -1) err(EX_IOERR, "Could not close input");
 }