summaryrefslogtreecommitdiff
path: root/usr/src/boot/common/util.c
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2022-02-22 18:00:48 -0600
committerRichard Lowe <richlowe@richlowe.net>2022-02-22 18:00:48 -0600
commit3971085411b91c5d82e278443ab68fca1946cb21 (patch)
tree8e6d01d8aea1c3d8179a47b929ff5bfa8b42f752 /usr/src/boot/common/util.c
parent1df45418ec3688847e142a9a2213965459ff39c7 (diff)
parentca783257c986cddcc674ae22916a6766b98a2d36 (diff)
downloadillumos-joyent-3971085411b91c5d82e278443ab68fca1946cb21.tar.gz
Merge branch 'master' of https://github.com/illumos/illumos-gate into man/big-reorg
# Conflicts: # usr/src/cmd/fmthard/fmthard.c # usr/src/cmd/zoneadmd/zcons.c # usr/src/man/man2/chmod.2 # usr/src/man/man2/close.2 # usr/src/man/man2/open.2 # usr/src/man/man3c/grantpt.3c # usr/src/man/man3c/posix_openpt.3c # usr/src/man/man3c/ptsname.3c # usr/src/man/man3c/unlockpt.3c # usr/src/man/man3utempter/utempter_add_record.3utempter # usr/src/man/man4/Makefile # usr/src/man/man4d/ptm.4d # usr/src/man/man4d/pts.4d # usr/src/man/man4d/pty.4d # usr/src/man/man4d/zcons.4d # usr/src/man/man4m/pckt.4m # usr/src/man/man4m/ptem.4m # usr/src/man/man4p/vxlan.7p # usr/src/man/man5/Makefile # usr/src/man/man5/bhyve_config.5 # usr/src/man/man7d/Makefile # usr/src/man/man7p/Makefile # usr/src/man/man8/bhyve.8 # usr/src/man/man8/dladm.8 # usr/src/man/man8/flowadm.8 # usr/src/man/man8/fmthard.8 # usr/src/man/man8/in.rlogind.8 # usr/src/man/man8/in.telnetd.8 # usr/src/man/man8/nvmeadm.8 # usr/src/man/man8/pppd.8 # usr/src/pkg/manifests/SUNWcs.man4d.inc # usr/src/uts/common/io/zcons.c
Diffstat (limited to 'usr/src/boot/common/util.c')
-rw-r--r--usr/src/boot/common/util.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/usr/src/boot/common/util.c b/usr/src/boot/common/util.c
new file mode 100644
index 0000000000..d73d992105
--- /dev/null
+++ b/usr/src/boot/common/util.c
@@ -0,0 +1,182 @@
+/*-
+ * Copyright (c) 1998 Robert Nordier
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are freely
+ * permitted provided that the above copyright notice and this
+ * paragraph and the following disclaimer are duplicated in all
+ * such forms.
+ *
+ * This software is provided "AS IS" and without any express or
+ * implied warranties, including, without limitation, the implied
+ * warranties of merchantability and fitness for a particular
+ * purpose.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <stdarg.h>
+
+#include "cons.h"
+#include "util.h"
+
+void
+memcpy(void *dst, const void *src, int len)
+{
+ const char *s = src;
+ char *d = dst;
+
+ while (len--)
+ *d++ = *s++;
+}
+
+void
+memset(void *b, int c, size_t len)
+{
+ char *bp = b;
+
+ while (len--)
+ *bp++ = (unsigned char)c;
+}
+
+int
+memcmp(const void *b1, const void *b2, size_t len)
+{
+ const unsigned char *p1, *p2;
+
+ for (p1 = b1, p2 = b2; len > 0; len--, p1++, p2++) {
+ if (*p1 != *p2)
+ return ((*p1) - (*p2));
+ }
+ return (0);
+}
+
+int
+strcmp(const char *s1, const char *s2)
+{
+
+ for (; *s1 == *s2 && *s1 != '\0'; s1++, s2++)
+ ;
+ return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+int
+strncmp(const char *s1, const char *s2, size_t len)
+{
+
+ for (; len > 0 && *s1 == *s2 && *s1 != '\0'; len--, s1++, s2++)
+ ;
+ return (len == 0 ? 0 : (unsigned char)*s1 - (unsigned char)*s2);
+}
+
+void
+strcpy(char *dst, const char *src)
+{
+
+ while (*src != '\0')
+ *dst++ = *src++;
+ *dst = '\0';
+}
+
+void
+strcat(char *dst, const char *src)
+{
+
+ while (*dst != '\0')
+ dst++;
+ while (*src != '\0')
+ *dst++ = *src++;
+ *dst = '\0';
+}
+
+char *
+strchr(const char *s, char ch)
+{
+
+ for (; *s != '\0'; s++) {
+ if (*s == ch)
+ return ((char *)(uintptr_t)(const void *)s);
+ }
+ return (NULL);
+}
+
+size_t
+strlen(const char *s)
+{
+ size_t len = 0;
+
+ while (*s++ != '\0')
+ len++;
+ return (len);
+}
+
+int
+printf(const char *fmt, ...)
+{
+ va_list ap;
+ const char *hex = "0123456789abcdef";
+ char buf[32], *s;
+ uint16_t *S;
+ unsigned long long u;
+ int c, l;
+
+ va_start(ap, fmt);
+ while ((c = *fmt++) != '\0') {
+ if (c != '%') {
+ putchar(c);
+ continue;
+ }
+ l = 0;
+nextfmt:
+ c = *fmt++;
+ switch (c) {
+ case 'l':
+ l++;
+ goto nextfmt;
+ case 'c':
+ putchar(va_arg(ap, int));
+ break;
+ case 's':
+ for (s = va_arg(ap, char *); *s != '\0'; s++)
+ putchar(*s);
+ break;
+ case 'S': /* Assume console can cope with wide chars */
+ for (S = va_arg(ap, uint16_t *); *S != 0; S++)
+ putchar(*S);
+ break;
+ case 'd': /* A lie, always prints unsigned */
+ case 'u':
+ case 'x':
+ switch (l) {
+ case 2:
+ u = va_arg(ap, unsigned long long);
+ break;
+ case 1:
+ u = va_arg(ap, unsigned long);
+ break;
+ default:
+ u = va_arg(ap, unsigned int);
+ break;
+ }
+ s = buf;
+ if (c == 'd' || c == 'u') {
+ do
+ *s++ = '0' + (u % 10U);
+ while (u /= 10);
+ } else {
+ do
+ *s++ = hex[u & 0xfu];
+ while (u >>= 4);
+ }
+ while (--s >= buf)
+ putchar(*s);
+ break;
+ }
+ }
+ va_end(ap);
+ return (0);
+}