xref: /csrg-svn/local/local.cmd/20b.c (revision 33482)
130246Smckusick /*
230246Smckusick  * Copyright (c) 1986 Regents of the University of California.
333478Sbostic  * All rights reserved.
433478Sbostic  *
533478Sbostic  * Redistribution and use in source and binary forms are permitted
633478Sbostic  * provided that this notice is preserved and that due credit is given
733478Sbostic  * to the University of California at Berkeley. The name of the University
833478Sbostic  * may not be used to endorse or promote products derived from this
933478Sbostic  * software without specific prior written permission. This software
1033478Sbostic  * is provided ``as is'' without express or implied warranty.
1130246Smckusick  */
1230246Smckusick 
1330246Smckusick #ifndef lint
1430246Smckusick char copyright[] =
1530246Smckusick "@(#) Copyright (c) 1986 Regents of the University of California.\n\
1630246Smckusick  All rights reserved.\n";
1733478Sbostic #endif /* not lint */
1830246Smckusick 
1930246Smckusick #ifndef lint
20*33482Sbostic static char sccsid[] = "@(#)20b.c	5.3 (Berkeley) 02/09/88";
2133478Sbostic #endif /* not lint */
2230246Smckusick 
23*33482Sbostic #include <stdio.h>
24*33482Sbostic 
25*33482Sbostic main(argc, argv)
26*33482Sbostic 	int argc;
27*33482Sbostic 	char **argv;
2830246Smckusick {
29*33482Sbostic 	register int bsize, cc, want;
3030246Smckusick 	register char *base, *current;
3130246Smckusick 	char *alloca();
3230246Smckusick 
33*33482Sbostic 	if (argc > 1) {
34*33482Sbostic 		bsize = atoi(argv[1]);
35*33482Sbostic 		if (bsize <= 0) {
36*33482Sbostic 			fputs("20b: bad block size.\n", stderr);
37*33482Sbostic 			exit(-1);
38*33482Sbostic 		}
39*33482Sbostic 	}
40*33482Sbostic 	base = alloca(bsize);
41*33482Sbostic 	for (cc = bsize; cc > 0;) {
4230246Smckusick 		current = base;
43*33482Sbostic 		for (want = bsize; want > 0 && cc > 0; want -= cc) {
4433478Sbostic 			if ((cc = read(0, current, want)) < 0)
4533478Sbostic 				return(-1);
4630246Smckusick 			current += cc;
4730246Smckusick 		}
48*33482Sbostic 		want = bsize - want;
4933478Sbostic 		if (want && write(1, base, want) != want)
5033478Sbostic 			return(-1);
5130246Smckusick 	}
5230246Smckusick 	return(0);
5330246Smckusick }
54