4.4BSD/usr/src/old/gets/gets.c

Compare this file to the similar file:
Show the results in this format:

static char *sccsid = "@(#)gets.c	4.2 (Berkeley) 6/19/81";
#include <stdio.h>

/*
 * gets [ default ]
 *
 *      read a line from standard input, echoing to std output
 *      if an error occurs just return "default"
 *      if no default and error exit abnormally
 */
main(argc, argv)
	int argc;
	char *argv[];
{
	char buf[BUFSIZ];
	
	setbuf(stdin, NULL);
	if (gets(buf) == NULL || buf[0] < ' ') {
		if (argc == 1)
			exit(1);
		strcpy(buf,argv[1]);
	}
	printf("%s\n", buf);
	exit(0);
}