home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
f
/
ftp-102.zip
/
ftape-1.02
/
qic
/
reblock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-12
|
2KB
|
90 lines
/* Reblock a pipeline.
Copyright (C) 1992 David L. Brown, Jr.
This program 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 program 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 program; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
* reblock.c,v 1.2 1992/10/13 01:55:35 dbrown Exp
*
* reblock.c,v
* Revision 1.2 1992/10/13 01:55:35 dbrown
* Added FSF copyright.
*
* Revision 1.1 1992/10/12 05:16:14 dbrown
* Created.
*
*/
#include <stdio.h>
main (int argc, char **argv)
{
int value = -1;
char *ptr;
int size;
int len;
int write_cur;
int read_cur;
int done = 0;
if (argc == 2)
value = atoi (argv[1]);
if (value <= 0)
{
fprintf (stderr, "Usage: reblock kbytes\n");
exit (1);
}
size = value * 1024;
ptr = (char *) malloc (size);
if (ptr == 0)
{
fprintf (stderr, "Cannot allocate %dk of data\n", value);
exit (1);
}
while (!done)
{
/* Read as much as possible in. */
read_cur = 0;
while (read_cur < size && !done)
{
len = read (0, ptr + read_cur, size - read_cur);
if (len <= 0)
done = 1;
else
read_cur += len;
}
/* Now write this data out. */
write_cur = 0;
while (write_cur < read_cur)
{
len = write (1, ptr + write_cur, read_cur - write_cur);
if (len <= 0)
{
fprintf (stderr, "Reblock error: can't write");
exit (1);
}
write_cur += len;
}
}
exit (0);
}