+/* Return the home directory of the current user */
+char *pa_get_home(char *s, size_t l) {
+ char *e;
+ char buf[1024];
+ struct passwd pw, *r;
+ assert(s && l);
+
+ if ((e = getenv("HOME")))
+ return pa_strlcpy(s, e, l);
+
+ if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r)
+ return NULL;
+
+ return pa_strlcpy(s, r->pw_dir, l);
+}
+
+/* Similar to OpenBSD's strlcpy() function */
+char *pa_strlcpy(char *b, const char *s, size_t l) {
+ assert(b && s && l > 0);
+
+ strncpy(b, s, l);
+ b[l-1] = 0;
+ return b;
+}
+
+/* Calculate the difference between the two specfified timeval
+ * timestamsps. */