summaryrefslogtreecommitdiff
path: root/usr/src/common
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2020-09-16 22:45:34 +0300
committerToomas Soome <tsoome@me.com>2020-09-25 20:34:45 +0300
commit28de4f3c3209c81f9a96e2019d44a0b9adcb74cb (patch)
tree4ef303f9cfefbd28622d901f115d8f3e717ab886 /usr/src/common
parent3e1c5f3a80260eb14c78730bcaca9e6c74f528a0 (diff)
downloadillumos-gate-28de4f3c3209c81f9a96e2019d44a0b9adcb74cb.tar.gz
13173 loader: add strtoul, strtoull, memmem and abort
Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org> Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/common')
-rw-r--r--usr/src/common/util/explicit_bzero.c21
-rw-r--r--usr/src/common/util/memmem.c87
-rw-r--r--usr/src/common/util/strtol.c22
-rw-r--r--usr/src/common/util/strtoll.c24
-rw-r--r--usr/src/common/util/strtoul.c24
-rw-r--r--usr/src/common/util/strtoull.c26
6 files changed, 174 insertions, 30 deletions
diff --git a/usr/src/common/util/explicit_bzero.c b/usr/src/common/util/explicit_bzero.c
new file mode 100644
index 0000000000..bcc7fa3f88
--- /dev/null
+++ b/usr/src/common/util/explicit_bzero.c
@@ -0,0 +1,21 @@
+/* $OpenBSD: explicit_bzero.c,v 1.3 2014/06/21 02:34:26 matthew Exp $ */
+/*
+ * Public domain.
+ * Written by Matthew Dempsky.
+ */
+
+#include <string.h>
+
+#pragma weak __explicit_bzero_hook
+
+void
+__explicit_bzero_hook(void *buf __unused, size_t len __unused)
+{
+}
+
+void
+explicit_bzero(void *buf, size_t len)
+{
+ (void) memset(buf, 0, len);
+ __explicit_bzero_hook(buf, len);
+}
diff --git a/usr/src/common/util/memmem.c b/usr/src/common/util/memmem.c
new file mode 100644
index 0000000000..a0f396e7c4
--- /dev/null
+++ b/usr/src/common/util/memmem.c
@@ -0,0 +1,87 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+
+/*
+ * Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+/*
+ * Find the first occurrence of the byte string s in byte string l.
+ */
+
+void *
+memmem(const void *l, size_t l_len, const void *s, size_t s_len)
+{
+ char *cur, *last;
+ const char *cl = (const char *)l;
+ const char *cs = (const char *)s;
+
+ /* we need something to compare */
+ if (l_len == 0 || s_len == 0)
+ return (NULL);
+
+ /* "s" must be smaller or equal to "l" */
+ if (l_len < s_len)
+ return (NULL);
+
+ /* special case where s_len == 1 */
+ if (s_len == 1)
+ return (memchr(l, (int)*cs, l_len));
+
+ /* the last position where its possible to find "s" in "l" */
+ last = (char *)cl + l_len - s_len;
+
+ for (cur = (char *)cl; cur <= last; cur++)
+ if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
+ return (cur);
+
+ return (NULL);
+}
diff --git a/usr/src/common/util/strtol.c b/usr/src/common/util/strtol.c
index e46e86b7d1..aeed49ca83 100644
--- a/usr/src/common/util/strtol.c
+++ b/usr/src/common/util/strtol.c
@@ -29,18 +29,25 @@
*/
/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
#if defined(_KERNEL) && !defined(_BOOT)
+#include <sys/null.h>
#include <sys/errno.h>
#else /* _KERNEL && !_BOOT */
-#if !defined(_BOOT) && !defined(_KMDB)
+#if !defined(_BOOT) && !defined(_KMDB) && !defined(_STANDALONE)
#include "lint.h"
-#endif /* !_BOOT && !_KMDB */
+#endif /* !_BOOT && !_KMDB && !_STANDALONE */
+#if defined(_STANDALONE)
+#include <sys/cdefs.h>
+#include <stand.h>
+#include <limits.h>
+#else
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
+#endif /* _STANDALONE */
#endif /* _KERNEL && !_BOOT */
#include "strtolctype.h"
#include <sys/types.h>
@@ -62,7 +69,7 @@ strtol(const char *str, char **nptr, int base)
const char **ptr = (const char **)nptr;
const unsigned char *ustr = (const unsigned char *)str;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr; /* in case no number is formed */
if (base < 0 || base > MBASE || base == 1) {
/* base is invalid -- should be a fatal error */
@@ -84,13 +91,14 @@ strtol(const char *str, char **nptr, int base)
c = *++ustr;
}
}
- if (base == 0)
+ if (base == 0) {
if (c != '0')
base = 10;
else if (ustr[1] == 'x' || ustr[1] == 'X')
base = 16;
else
base = 8;
+ }
/*
* for any base > 10, the digits incrementally following
* 9 are assumed to be "abc...z" or "ABC...Z"
@@ -125,7 +133,7 @@ strtol(const char *str, char **nptr, int base)
val -= xx;
c = *++ustr;
}
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
*result = neg ? val : -val;
@@ -137,7 +145,7 @@ strtol(const char *str, char **nptr, int base)
overflow:
for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; (c = *++ustr))
;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
return (ERANGE);
diff --git a/usr/src/common/util/strtoll.c b/usr/src/common/util/strtoll.c
index 6e654c9ed5..05dcdd56da 100644
--- a/usr/src/common/util/strtoll.c
+++ b/usr/src/common/util/strtoll.c
@@ -25,18 +25,27 @@
*/
/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
#if defined(_KERNEL) && !defined(_BOOT)
+#include <sys/null.h>
#include <sys/errno.h>
#else /* _KERNEL && !_BOOT */
-#if !defined(_BOOT) && !defined(_KMDB)
+#if !defined(_BOOT) && !defined(_KMDB) && !defined(_STANDALONE)
#include "lint.h"
-#endif /* !_BOOT && !_KMDB */
+#endif /* !_BOOT && !_KMDB && !_STANDALONE */
+#if defined(_STANDALONE)
+#include <sys/cdefs.h>
+#include <stand.h>
+#include <limits.h>
+
+typedef long long longlong_t;
+#else
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
+#endif /* _STANDALONE */
#endif /* _KERNEL && !_BOOT */
#include "strtolctype.h"
#include <sys/types.h>
@@ -58,7 +67,7 @@ strtoll(const char *str, char **nptr, int base)
const char **ptr = (const char **)nptr;
const unsigned char *ustr = (const unsigned char *)str;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr; /* in case no number is formed */
if (base < 0 || base > MBASE || base == 1) {
/* base is invalid -- should be a fatal error */
@@ -80,13 +89,14 @@ strtoll(const char *str, char **nptr, int base)
c = *++ustr;
}
}
- if (base == 0)
+ if (base == 0) {
if (c != '0')
base = 10;
else if (ustr[1] == 'x' || ustr[1] == 'X')
base = 16;
else
base = 8;
+ }
/*
* for any base > 10, the digits incrementally following
* 9 are assumed to be "abc...z" or "ABC...Z"
@@ -120,7 +130,7 @@ strtoll(const char *str, char **nptr, int base)
val -= xx;
c = *++ustr;
}
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
*result = neg ? val : -val;
@@ -132,7 +142,7 @@ strtoll(const char *str, char **nptr, int base)
overflow:
for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; (c = *++ustr))
;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
return (ERANGE);
diff --git a/usr/src/common/util/strtoul.c b/usr/src/common/util/strtoul.c
index 3b1eff90c1..f890afc262 100644
--- a/usr/src/common/util/strtoul.c
+++ b/usr/src/common/util/strtoul.c
@@ -25,18 +25,25 @@
*/
/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
#if defined(_KERNEL) && !defined(_BOOT)
+#include <sys/null.h>
#include <sys/errno.h>
#else /* _KERNEL && !_BOOT */
-#if !defined(_BOOT) && !defined(_KMDB)
+#if !defined(_BOOT) && !defined(_KMDB) && !defined(_STANDALONE)
#include "lint.h"
-#endif /* !_BOOT && !_KMDB */
+#endif /* !_BOOT && !_KMDB && !_STANDALONE */
+#if defined(_STANDALONE)
+#include <sys/cdefs.h>
+#include <stand.h>
+#include <limits.h>
+#else
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
+#endif /* _STANDALONE */
#endif /* _KERNEL && !_BOOT */
#include "strtolctype.h"
#include <sys/types.h>
@@ -57,7 +64,7 @@ strtoul(const char *str, char **nptr, int base)
const char **ptr = (const char **)nptr;
const unsigned char *ustr = (const unsigned char *)str;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr; /* in case no number is formed */
if (base < 0 || base > MBASE || base == 1) {
/* base is invalid -- should be a fatal error */
@@ -79,13 +86,14 @@ strtoul(const char *str, char **nptr, int base)
c = *++ustr;
}
}
- if (base == 0)
+ if (base == 0) {
if (c != '0')
base = 10;
else if (ustr[1] == 'x' || ustr[1] == 'X')
base = 16;
else
base = 8;
+ }
/*
* for any base > 10, the digits incrementally following
* 9 are assumed to be "abc...z" or "ABC...Z"
@@ -108,12 +116,12 @@ strtoul(const char *str, char **nptr, int base)
if (val > multmax)
goto overflow;
val *= base;
- if (ULONG_MAX - val < xx)
+ if (ULONG_MAX - val < (unsigned long)xx)
goto overflow;
val += xx;
c = *++ustr;
}
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
*result = neg ? -val : val;
@@ -125,7 +133,7 @@ strtoul(const char *str, char **nptr, int base)
overflow:
for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; (c = *++ustr))
;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
return (ERANGE);
diff --git a/usr/src/common/util/strtoull.c b/usr/src/common/util/strtoull.c
index ca7713d524..4a415f37d2 100644
--- a/usr/src/common/util/strtoull.c
+++ b/usr/src/common/util/strtoull.c
@@ -25,18 +25,27 @@
*/
/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
#if defined(_KERNEL) && !defined(_BOOT)
+#include <sys/null.h>
#include <sys/errno.h>
#else /* _KERNEL && !_BOOT */
-#if !defined(_BOOT) && !defined(_KMDB)
+#if !defined(_BOOT) && !defined(_KMDB) && !defined(_STANDALONE)
#include "lint.h"
-#endif /* !_BOOT && !_KMDB */
+#endif /* !_BOOT && !_KMDB && !_STANDALONE */
+#if defined(_STANDALONE)
+#include <sys/cdefs.h>
+#include <stand.h>
+#include <limits.h>
+
+typedef unsigned long long u_longlong_t;
+#else
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
+#endif /* _STANDALONE */
#endif /* _KERNEL && !_BOOT */
#include "strtolctype.h"
#include <sys/types.h>
@@ -57,7 +66,7 @@ strtoull(const char *str, char **nptr, int base)
const char **ptr = (const char **)nptr;
const unsigned char *ustr = (const unsigned char *)str;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr; /* in case no number is formed */
if (base < 0 || base > MBASE || base == 1) {
/* base is invalid -- should be a fatal error */
@@ -79,13 +88,14 @@ strtoull(const char *str, char **nptr, int base)
c = *++ustr;
}
}
- if (base == 0)
+ if (base == 0) {
if (c != '0')
base = 10;
else if (ustr[1] == 'x' || ustr[1] == 'X')
base = 16;
else
base = 8;
+ }
/*
* for any base > 10, the digits incrementally following
* 9 are assumed to be "abc...z" or "ABC...Z"
@@ -108,12 +118,12 @@ strtoull(const char *str, char **nptr, int base)
if (val > multmax)
goto overflow;
val *= base;
- if (ULLONG_MAX - val < xx)
+ if (ULLONG_MAX - val < (unsigned long long)xx)
goto overflow;
val += xx;
c = *++ustr;
}
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
*result = neg ? -val : val;
@@ -125,7 +135,7 @@ strtoull(const char *str, char **nptr, int base)
overflow:
for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; (c = *++ustr))
;
- if (ptr != (const char **)0)
+ if (ptr != NULL)
*ptr = (char *)ustr;
#if defined(_KERNEL) && !defined(_BOOT)
return (ERANGE);