chiark / gitweb /
Working on debianisation and packaging.
[chiark-utils.git] / backup / writebuffer.c
index c4fa9e72e45081f5d320c6b5fb1242c933f39240..aaff8d7859d48a30899fa93d21a3cf3158591597 100644 (file)
@@ -1,4 +1,31 @@
-/**/
+/*
+ * writebuffer.c
+ *
+ * A program for writing output to devices which don't like constant
+ * stopping and starting, such as tape drives.  writebuffer is:
+ *  Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
+ *
+ * writebuffer is part of chiark backup, a system for backing up GNU/Linux
+ * and other UN*X-compatible machines, as used on chiark.greenend.org.uk.
+ * chiark backup is:
+ *  Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
+ *  Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this file; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <sys/time.h>
 #include <sys/types.h>
@@ -7,7 +34,11 @@
 #include <errno.h>
 #include <unistd.h>
 
-#define BUFFER 16*1024*1024
+#ifndef RWBUFFER_SIZE_MB
+#define RWBUFFER_SIZE_MB 16
+#endif
+
+#define BUFFER (RWBUFFER_SIZE_MB*1024*1024)
 #define WAITFILL ((BUFFER*3)/4)
 
 static inline int min(int a, int b) { return a<=b ? a : b; }
@@ -19,7 +50,7 @@ static void nonblock(int fd) {
   if (fcntl(fd,F_SETFL,r) == -1) { perror("fcntl setfl"); exit(1); }
 }
 
-int main(void) {
+int main(int argc, const char *const *argv) {
   static unsigned char buf[BUFFER];
   
   unsigned char *wp, *rp;
@@ -27,6 +58,11 @@ int main(void) {
   fd_set readfds;
   fd_set writefds;
 
+  if (argv[1]) {
+    fputs("readbuffer: no arguments allowed\n", stderr);
+    exit(-1);
+  }
+
   used=0; wp=rp=buf; writing=0; seeneof=0;
   nonblock(0); nonblock(1);
   while (!seeneof || used) {