usr.bin/split/split.c
/*
 * split1 --
 *	Split the input by bytes.
 */
split1
Split the input by bytes.
split1 Split the input by bytes .
void
split1()
{
	long bcnt;
	int dist, len;
	char *C;
	for (bcnt = 0;;)
		switch (len = read(ifd, bfr, MAXBSIZE)) {
		case 0:
			exit(0);
		case -1:
			err(1, "read");
		default:
			if (!file_open) {
				newfile();
				file_open = 1;
			}
			if (bcnt + len >= bytecnt) {
				dist = bytecnt - bcnt;
				if (write(ofd, bfr, dist) != dist)
					err(1, "write");
				len -= dist;
				for (C = bfr + dist; len >= bytecnt;
				    len -= bytecnt, C += bytecnt) {
					newfile();
					if (write(ofd,
					    C, (int)bytecnt) != bytecnt)
						err(1, "write");
				}
				if (len) {
					newfile();
					if (write(ofd, C, len) != len)
						err(1, "write");
				} else
					file_open = 0;
				bcnt = len;
			} else {
				bcnt += len;
				if (write(ofd, bfr, len) != len)
					err(1, "write");
			}
		}
}
void split1 ( ) { long bcnt ; int dist , len ; char * C ; for ( bcnt = 0 ; ; ) switch ( len = read ( ifd , bfr , MAXBSIZE ) ) { case 0 : exit ( 0 ) ; case -1 : err ( 1 , " " ) ; default : if ( ! file_open ) { newfile ( ) ; file_open = 1 ; } if ( bcnt + len >= bytecnt ) { dist = bytecnt - bcnt ; if ( write ( ofd , bfr , dist ) != dist ) err ( 1 , " " ) ; len -= dist ; for ( C = bfr + dist ; len >= bytecnt ; len -= bytecnt , C += bytecnt ) { newfile ( ) ; if ( write ( ofd , C , ( int ) bytecnt ) != bytecnt ) err ( 1 , " " ) ; } if ( len ) { newfile ( ) ; if ( write ( ofd , C , len ) != len ) err ( 1 , " " ) ; } else file_open = 0 ; bcnt = len ; } else { bcnt += len ; if ( write ( ofd , bfr , len ) != len ) err ( 1 , " " ) ; } } }
split1
      Split the input by bytes.
split1 Split the input by bytes .
/* NOTREACHED */