File:  [Research Unix] / researchv10no / cmd / zero.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:34 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

#include	<stdlib.h>
#include	<limits.h>
#include	<stdio.h>

#define		BLOCK		(32*1024)

main(int argc, char **argv)
{
	int byte = 0;
	long nbytes = LONG_MAX;
	char buf[BLOCK];

	if(argc > 3){
		fprintf(stderr, "Usage: zero [byte [nbytes]]\n");
		exit(1);
	}
	if(argc > 1)
		byte = strtol(argv[1], (char **)0, 0);
	if(argc > 2)
		nbytes = strtol(argv[2], (char **)0, 0);
	memset(buf, byte, BLOCK);
	while(nbytes > BLOCK){
		if(write(1, buf, BLOCK) != BLOCK){
			perror("zero: write error");
			exit(2);
		}
		nbytes -= BLOCK;
	}
	if(nbytes){
		if(write(1, buf, (int)nbytes) != (int)nbytes){
			perror("zero: write error");
			exit(2);
		}
	}
	exit(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.