aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ctm/ctm_rmail/error.c
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>1995-01-31 19:12:53 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>1995-01-31 19:12:53 +0000
commite86e7d0e07c7c5ae4f14802275bdc28593c4a395 (patch)
treeae79e489e88f13e3489752b714035c0bcbd71c2a /usr.sbin/ctm/ctm_rmail/error.c
parente322e6a55ac09769d65d599baf79bb4c4d6f29aa (diff)
downloadsrc-e86e7d0e07c7c5ae4f14802275bdc28593c4a395.tar.gz
src-e86e7d0e07c7c5ae4f14802275bdc28593c4a395.zip
CTM email tools.
Reviewed by: phk Submitted by: Stephen McKay <syssgm@devetir.qld.gov.au>
Notes
Notes: svn path=/head/; revision=6081
Diffstat (limited to 'usr.sbin/ctm/ctm_rmail/error.c')
-rw-r--r--usr.sbin/ctm/ctm_rmail/error.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/usr.sbin/ctm/ctm_rmail/error.c b/usr.sbin/ctm/ctm_rmail/error.c
new file mode 100644
index 000000000000..be3581d4aaed
--- /dev/null
+++ b/usr.sbin/ctm/ctm_rmail/error.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+#include "error.h"
+
+static FILE *error_fp = NULL;
+static char *prog = NULL;
+
+
+/*
+ * Log errors to the given file.
+ */
+void
+err_set_log(char *log_file)
+ {
+ FILE *fp;
+
+ if ((fp = fopen(log_file, "a")) == NULL)
+ err("cannot log to '%s'", log_file);
+ else
+ error_fp = fp;
+ }
+
+
+/*
+ * Set the error prefix if not logging to a file.
+ */
+void
+err_prog_name(char *name)
+ {
+ if ((prog = strrchr(name, '/')) == NULL)
+ prog = name;
+ else
+ prog++;
+ }
+
+
+/*
+ * Log an error.
+ */
+void
+err(char *fmt, ...)
+ {
+ va_list ap;
+ time_t now;
+ struct tm *tm;
+ FILE *fp;
+
+ if ((fp = error_fp) == NULL)
+ {
+ fp = stderr;
+ if (prog != NULL)
+ fprintf(fp, "%s: ", prog);
+ }
+ else
+ {
+ time(&now);
+ tm = localtime(&now);
+ fprintf(fp, "%04d-%02d-%02d %02d:%02d ", tm->tm_year+1900,
+ tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+ }
+
+ va_start(ap, fmt);
+ vfprintf(fp, fmt, ap);
+ va_end(ap);
+
+ fprintf(fp, "\n");
+ fflush(fp);
+ }