File:  [MW Coherent from dump] / coherent / d / usr / src / examples / fdopen.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#include <ctype.h>
#include <stdio.h>

void adios();

main(argc, argv)
int argc; char *argv[];
{
	extern FILE *fdopen();
	FILE *fd;
	int fo;
	int holder;

	if (--argc != 1)
		adios("Usage: fdopen example_filename");
	if ((fo = open(argv[1], 0)) == -1)
		adios("open failed.");
	if ((fd = fdopen(fo, "r")) == NULL)
		adios("fdopen failed.");

	while ((holder = fgetc(fd)) != EOF) {
		if ((holder > '\177') && (holder < ' '))
			switch(holder) {
				case '\t':
				case '\n':
					break;
				default:
					fprintf(stderr, 
					"Seeing char %d\n", holder);
					exit(1);
			}
		fputc(holder, stdout);
	}
	exit(0);
}

void adios(message)
char *message;
{
	fprintf(stderr, "%s\n", message);
	exit(1);
}

unix.superglobalmegacorp.com

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