+
+/*
+ * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer,
+ * always leaves destination null-terminated (for len > 0).
+ */
+void
+strlcpy(char *dest, size_t len, const char *src)
+{
+ if (len == 0)
+ return;
+ if (strlen(src) < len)
+ strcpy(dest, src);
+ else {
+ strncpy(dest, src, len - 1);
+ dest[len-1] = 0;
+ }
+}
+
+/*
+ * strlcat - like strcat/strncat, doesn't overflow destination buffer,
+ * always leaves destination null-terminated (for len > 0).
+ */
+void
+strlcat(char *dest, size_t len, const char *src)
+{
+ size_t dlen;
+
+ if (len == 0)
+ return;
+ dlen = strlen(dest);
+ if (dlen < len - 1)
+ strlcpy(dest + dlen, len - dlen, src);
+}
+
+/*
+ * fatal - log an error message and die horribly.
+ */
+void
+fatal __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_ERR, "%s", line);
+
+ die(1); /* as promised */
+}
+
+/*
+ * error - log an error message.
+ */
+void
+error __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_ERR, "%s", line);
+}
+
+/*
+ * warn - log a warning message.
+ */
+void
+warn __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_WARNING, "%s", line);
+}
+
+/*
+ * notice - log a notice-level message.
+ */
+void
+notice __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_NOTICE, "%s", line);
+}
+
+/*
+ * info - log an informational message.
+ */
+void
+info __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_INFO, "%s", line);
+}
+
+/*
+ * dbglog - log a debug message.
+ */
+void
+dbglog __V((char *fmt, ...))
+{
+ va_list pvar;
+
+#if __STDC__
+ va_start(pvar, fmt);
+#else
+ char *fmt;
+ va_start(pvar);
+ fmt = va_arg(pvar, char *);
+#endif
+
+ vslprintf(line, sizeof(line), fmt, pvar);
+ va_end(pvar);
+
+ syslog(LOG_DEBUG, "%s", line);
+}