err(1, fname);
err(1, "%s", fname);
main(argc, argv)	int argc;	char *argv[];{	register int cc;	struct termios rtt;	struct winsize win;	int aflg, ch;	char ibuf[BUFSIZ];	aflg = 0;	while ((ch = getopt(argc, argv, "a")) != -1)		switch(ch) {		case 'a':			aflg = 1;			break;		case '?':		default:			(void)fprintf(stderr, "usage: script [-a] [file]\n");			exit(1);		}	argc -= optind;	argv += optind;	if (argc > 0)		fname = argv[0];	else		fname = "typescript";	if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL)		err(1, fname);	(void)tcgetattr(STDIN_FILENO, &tt);	(void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);	if (openpty(&master, &slave, NULL, &tt, &win) == -1)		err(1, "openpty");	(void)printf("Script started, output file is %s\n", fname);	rtt = tt;	cfmakeraw(&rtt);	rtt.c_lflag &= ~ECHO;	(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);	(void)signal(SIGWINCH, handlesigwinch);	(void)signal(SIGCHLD, finish);	child = fork();	if (child < 0) {		perror("fork");		fail();	}	if (child == 0) {		subchild = child = fork();		if (child < 0) {			perror("fork");			fail();		}		if (child)			dooutput();		else			doshell();	}	(void)fclose(fscript);	while ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0)		(void)write(master, ibuf, cc);	done(0);}