+#ifdef DEBUG
+static void debug(char const *format, ...) {
+ va_list ap;
+
+ int saved_errno = errno;
+
+ /* If the file doesn't exist, do nothing. Prevents writing log files in
+ * unexpected places. The user must create the file manually. */
+ int fd = open(DEBUG_FILE, O_WRONLY | O_APPEND);
+ if (fd == -1) {
+ errno = saved_errno;
+ return;
+ }
+
+ static int call_count = 0;
+ call_count++;
+
+ va_start(ap, format);
+ debug_write(fd, call_count == 1, format, ap);
+ va_end(ap);
+
+ errno = saved_errno;
+}
+#endif
+
+static void warning(char const *format, ...) {
+ va_list ap;
+
+ int saved_errno = errno;
+
+ char const *home = getenv("HOME");
+ if (!home) {
+ errno = saved_errno;
+ return;
+ }
+
+ char path[strlen(home) + 1 + strlen(WARNING_FILE) + 1];
+ strcpy(path, home);
+ strcat(path, "/");
+ strcat(path, WARNING_FILE);
+
+ /* Create the warning file if it doesn't exist yet. */
+ int fd = open(path, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ errno = saved_errno;
+ return;
+ }
+
+ static int call_count = 0;
+ call_count++;
+
+ va_start(ap, format);
+ debug_write(fd, call_count == 1, format, ap);
+ va_end(ap);
+
+ errno = saved_errno;
+}
+