1
0

commands take buf, bad commmands dont segfault

Este cometimento está contido em:
bx 2022-04-02 11:59:31 +00:00
ascendente 5340cd4ef2
cometimento 39ab7a9055
5 ficheiros modificados com 11 adições e 6 eliminações

Ver ficheiro

@ -1,4 +1,5 @@
void
c_quit() {
c_quit(char *b) {
exit(0);
}

Ver ficheiro

@ -1,3 +1,3 @@
void (*commands[256])() = {
void (*commands[256])(char *) = {
NULL,
['q'] = c_quit,

7
efn.h
Ver ficheiro

@ -1,4 +1,7 @@
extern void (*commands[256])();
#include <stdlib.h>
#include "globals.h"
void c_quit();
extern void (*commands[256])(char *);
void c_quit(char *);

0
globals.h Ficheiro normal
Ver ficheiro

5
main.c
Ver ficheiro

@ -1,10 +1,11 @@
int
main(int argc, char **argv) {
static char buf[256];
while (1) {
while(1) {
char *com = fgets(buf, sizeof(buf), stdin);
if (com != NULL) {
commands[com[0]]();
if (commands[com[0]] != NULL) commands[com[0]](buf);
else puts("invalid command.");
}
}
return 0;