From 7f8952630abc0db42aa29cc0f2df4481789433bc Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 19 Feb 2014 11:11:49 +0100 Subject: Add error handling and unlink of created tmp files. --- main_simple.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'main_simple.c') diff --git a/main_simple.c b/main_simple.c index 60d57ac..84753c9 100644 --- a/main_simple.c +++ b/main_simple.c @@ -30,13 +30,17 @@ #include #include #include - +#include #include +#include +#include int main(int argc, char *argv[]) { - int fd = open("/tmp/my.log", O_CREAT | O_RDWR, 0777); + const char *mylog = "/tmp/my.log"; + int fd = open(mylog, O_CREAT | O_RDWR, 0777); if(fd == -1) { + printf("Could not open '%s' for writing: %s", mylog, strerror(errno)); return 1; } @@ -46,7 +50,7 @@ int main(int argc, char *argv[]) HUG_FLAG_OUTPUT_TO_STDERR | 0, HUG_OPTION_FD, fd, - HUG_OPTION_FILENAME, "/tmp/my2.log", + HUG_OPTION_FILENAME, "/tmp/my.log2", HUG_OPTION_STDOUT_NO_DATE, 0, HUG_OPTION_END); @@ -65,5 +69,8 @@ int main(int argc, char *argv[]) hug_close(); + unlink(mylog); + unlink("/tmp/my.log2"); + return 0; } -- cgit v1.2.3