Skip to content

cat-like program yields a kernel panic

A simple program like a cat will trigger an oops. As I'm not able to get informations with the USB, I'm porividing the culprit to you.

#include "cat.h"
#include "builtins.h"

#include <stdio.h>

static void usage(char *execname)
{
	printf("usage : %s file\n", execname);
}


int builtin_cat(char **args)
{
	if (args[1] == NULL || args[2] != NULL) {
		usage(args[0]);
		return -1;
	}

	FILE* file = NULL
	file = fopen(args[1], "r");
	if(file == NULL) {
		perror("cat");
		return -1;
	}
	int c = 0;
	while(!feof(file) && !ferror(file) && ++c < 100)
		putchar(fgetc(file));
	if(ferror(file)) {
		perror("ls");
		fclose(file);
		return -1;
	}
	fclose(file);
	return 0;

}