X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=backup%2Freadbuffer.c;h=e48e78c6ff9fd2819e4747ddd6565ec9c269e9b8;hp=b733fd6dc81a2b94c48026c1cdfdd2eb773a5634;hb=35eebe42ba3cd77674422cebf674e316d5a258b1;hpb=8e5f50513299d7d7f15d958579dc0b0751923ed1 diff --git a/backup/readbuffer.c b/backup/readbuffer.c index b733fd6..e48e78c 100644 --- a/backup/readbuffer.c +++ b/backup/readbuffer.c @@ -1,7 +1,15 @@ /* * readbuffer.c * - * Copyright (C) 1997,1998 Ian Jackson + * A program for reading input from devices which don't like constant + * stopping and starting, such as tape drives. readbuffer is: + * Copyright (C) 1997-1998,2000-2001 Ian Jackson + * + * readbuffer 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 + * Copyright (C) 1999 Peter Maydell * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -27,85 +35,57 @@ #include #include -#define BUFFER 16*1024*1024 -#define WAITEMPTY ((BUFFER*1)/4) +#include "rwbuffer.h" -static inline int min(int a, int b) { return a<=b ? a : b; } +const char *progname= "readbuffer"; -static void nonblock(int fd) { - int r; - r= fcntl(fd,F_GETFL,0); if (r == -1) { perror("fcntl getfl"); exit(1); } - r |= O_NDELAY; - if (fcntl(fd,F_SETFL,r) == -1) { perror("fcntl setfl"); exit(1); } -} +static size_t waitempty; int main(int argc, const char *const *argv) { - static unsigned char buf[BUFFER]; - - unsigned char *wp, *rp; - int used,r,reading,seeneof; - fd_set readfds; - fd_set writefds; - - used=0; wp=rp=buf; reading=1; seeneof=0; - nonblock(0); nonblock(1); - - if (argv[1] && !strcmp(argv[1],"--mlock")) { - if (mlock(buf,sizeof(buf))) { perror("mlock"); exit(1); } - argv++; argc--; - } - if (argv[1]) { fputs("usage: readbuffer [--mlock]\n",stderr); exit(1); } + int r,reading; + startup(argv); + waitempty= (buffersize*1)/4; + reading=1; + while (!seeneof || used) { + FD_ZERO(&readfds); if (reading) { - if (used