made die() variadic

This commit is contained in:
Noah Swerhun 2021-11-07 09:26:50 -06:00
parent 87aab37e05
commit 50b027df2e
3 changed files with 14 additions and 5 deletions

View file

@ -19,7 +19,7 @@ CARD* card_parse_csv(char *f, int *ct) {
CARD *ca = NULL; CARD *ca = NULL;
if ((fp = fopen(f, "r")) == NULL) if ((fp = fopen(f, "r")) == NULL)
die("failed to open file (null pointer)"); die("failed to open file '%s' (null pointer)", f);
*ct = 0; *ct = 0;

View file

@ -1,7 +1,7 @@
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H #define MAIN_H
void die(char *); void die(char *, ...);
char *fgetl(FILE *); char *fgetl(FILE *);
char *strdup_(char *); char *strdup_(char *);

View file

@ -1,13 +1,21 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ncurses.h> #include <ncurses.h>
#include "include/main.h" #include "include/main.h"
#include "include/card.h" #include "include/card.h"
void die(char *s) { void die(char *format, ...) {
fprintf(stderr, "fatal: %s\n", s); va_list args;
va_start(args, format);
fprintf(stderr, "fatal: ");
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
exit(1); exit(1);
} }
@ -27,7 +35,8 @@ void usage(void) {
exit(0); exit(0);
} }
char *fgetl(FILE *stream) { size_t s_sz = 1; // +1 for null byte char *fgetl(FILE *stream) {
size_t s_sz = 1; // +1 for null byte
char *s = NULL; char *s = NULL;
char c; char c;