summaryrefslogtreecommitdiffstats
path: root/usr.sbin/installboot/util.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2014-01-18 02:47:27 +0000
committerjsing <jsing@openbsd.org>2014-01-18 02:47:27 +0000
commit463390984eb0aed0f709cffa963f0c0c58a8ecf4 (patch)
tree09a2565bbe45d90713068dc07b72cb719d3805e1 /usr.sbin/installboot/util.c
parentBuild installboot on all architectures. (diff)
downloadwireguard-openbsd-463390984eb0aed0f709cffa963f0c0c58a8ecf4.tar.xz
wireguard-openbsd-463390984eb0aed0f709cffa963f0c0c58a8ecf4.zip
Add a -r flag that allows for the mount point of the root filesystem to be
specified. This is primarily for use by the installer and defaults to /.
Diffstat (limited to 'usr.sbin/installboot/util.c')
-rw-r--r--usr.sbin/installboot/util.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/usr.sbin/installboot/util.c b/usr.sbin/installboot/util.c
new file mode 100644
index 00000000000..77cdc048180
--- /dev/null
+++ b/usr.sbin/installboot/util.c
@@ -0,0 +1,43 @@
+/* $OpenBSD: util.c,v 1.1 2014/01/18 02:47:27 jsing Exp $ */
+
+/*
+ * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "installboot.h"
+
+char *
+fileprefix(const char *base, const char *path)
+{
+ char *r, *s;
+ int n;
+
+ if ((s = malloc(PATH_MAX)) == NULL)
+ err(1, "malloc");
+ n = snprintf(s, PATH_MAX, "%s/%s", base, path);
+ if (n < 1 || n >= PATH_MAX)
+ err(1, "snprintf");
+ if ((r = realpath(s, NULL)) == NULL)
+ err(1, "realpath");
+ free(s);
+
+ return r;
+}