Skip to content

Commit

Permalink
fatal error printing utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
uno20001 committed Apr 19, 2020
1 parent 9fefac2 commit 6197a0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ program = mktorrent
version = 1.1

HEADERS = mktorrent.h
SRCS = ftw.c init.c sha1.c hash.c output.c main.c
SRCS = ftw.c init.c sha1.c hash.c output.c main.c msg.c
19 changes: 19 additions & 0 deletions msg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "msg.h"


void fatal(const char *format, ...) {

va_list args;
va_start(args, format);

fputs("fatal error: ", stderr);
vfprintf(stderr, format, args);

va_end(args);

exit(EXIT_FAILURE);
}
10 changes: 10 additions & 0 deletions msg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef MKTORRENT_MSG_H
#define MKTORRENT_MSG_H

void fatal(const char *format, ...);


#define FATAL_IF(cond, format, ...) do { if (cond) fatal(format, __VA_ARGS__); } while(0)
#define FATAL_IF0(cond, format) do { if (cond) fatal(format); } while(0)

#endif /* MKTORRENT_MSG_H */

0 comments on commit 6197a0a

Please sign in to comment.