panthema / 2006 / SDIOS06 / sdios06 / src / cat / catmain.cc (Download File)
#include <config.h>

#include <stdio.h>

#include <sdi/log.h>

int main(int argc, char *argv[])
{
	int result = 0;
	
    for(int i = 1; i < argc; ++i) {
    	const char* filename = argv[i];
		FILE* file = fopen(filename, "r");
		if(!file) {
			fprintf(stderr, "Couldn't open file '%s'\n", filename);
			result = 1;
			continue;
		}
		
		while(feof(file) == 0) {
			char buf[64]; // small buffer, to force multiple fread calls...
			size_t res = fread(buf, 1, sizeof(buf), file);
			fwrite(buf, 1, res, stdout);
		}
		
		if(fclose(file) != 0) {
			fprintf(stderr, "Error when closing file\n");
			result = 1;
			continue;
		}
    }

	return result;
}

RSS 2.0 Weblog Feed Atom 1.0 Weblog Feed Valid XHTML 1.1 Valid CSS (2.1)
Copyright 2005-2014 Timo Bingmann - Impressum