pulled in and adapted the dos code from eradicate
[retrobench] / src / dos / logger.c
diff --git a/src/dos/logger.c b/src/dos/logger.c
new file mode 100644 (file)
index 0000000..70489ad
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "logger.h"
+
+int init_logger(const char *fname)
+{
+       int fd;
+       if((fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) {
+               fprintf(stderr, "init_logger: failed to open %s: %s\n", fname, strerror(errno));
+               return -1;
+       }
+
+       close(1);
+       close(2);
+       dup(fd);
+       dup(fd);
+       return 0;
+}