diff options
author | comex | 2015-01-29 21:49:37 -0500 |
---|---|---|
committer | comex | 2015-01-29 21:49:37 -0500 |
commit | 76a805974a7b177a4ea6b5587fe8551087ac1505 (patch) | |
tree | 84cef385a74b34e0cdd1489848f6da39ed032233 /ios-bootstrap/ib-log.h | |
parent | a bunch of stuff that should have been committed separately (diff) | |
download | substitute-76a805974a7b177a4ea6b5587fe8551087ac1505.tar.gz |
...
Diffstat (limited to 'ios-bootstrap/ib-log.h')
-rw-r--r-- | ios-bootstrap/ib-log.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ios-bootstrap/ib-log.h b/ios-bootstrap/ib-log.h new file mode 100644 index 0000000..f4b0b35 --- /dev/null +++ b/ios-bootstrap/ib-log.h @@ -0,0 +1,26 @@ +#pragma once +#include <dispatch/dispatch.h> +#include <stdio.h> +#include <unistd.h> + +static FILE *logfp; +static void open_logfp_if_necessary() { + /* syslog() doesn't seem to work from launchd... */ + static dispatch_once_t pred; + dispatch_once(&pred, ^{ + char filename[128]; + sprintf(filename, "/tmp/substitute-" IB_LOG_NAME "-log.%ld", + (long) getpid()); + logfp = fopen(filename, "w"); + if (!logfp) { + /* Ack... */ + logfp = stderr; + } + }); +} +#define ib_log(fmt, args...) do { \ + open_logfp_if_necessary(); \ + fprintf(logfp, fmt "\n", ##args); \ + fflush(logfp); \ +} while(0) + |