8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / common / util / memstr.c
blobf4e7289117dc86832fdce472e40d15c21c79b378
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25 #if defined(_BOOT)
26 #include <sys/salib.h>
27 #else
28 #include <sys/systm.h>
29 #endif
32 * Implementations of functions described in memory(3C).
33 * These functions match the section 3C manpages.
36 * The SunStudio compiler may generate calls to _memmove, _memset,
37 * and _memcpy; So we need to make sure that the correct symbols
38 * exist for these calls.
40 #pragma weak _memmove = memmove
41 void *
42 memmove(void *s1, const void *s2, size_t n)
44 #if defined(_BOOT)
45 bcopy(s2, s1, n);
46 #else
47 ovbcopy(s2, s1, n);
48 #endif
49 return (s1);
52 #pragma weak _memset = memset
53 void *
54 memset(void *s, int c, size_t n)
56 unsigned char *t;
58 if ((unsigned char)c == '\0')
59 bzero(s, n);
60 else {
61 for (t = (unsigned char *)s; n > 0; n--)
62 *t++ = (unsigned char)c;
64 return (s);
67 int
68 memcmp(const void *s1, const void *s2, size_t n)
70 const uchar_t *ps1 = s1;
71 const uchar_t *ps2 = s2;
73 if (s1 != s2 && n != 0) {
74 do {
75 if (*ps1++ != *ps2++)
76 return (ps1[-1] - ps2[-1]);
77 } while (--n != 0);
80 return (0);
83 #pragma weak _memcpy = memcpy
84 void *
85 memcpy(void *s1, const void *s2, size_t n)
87 bcopy(s2, s1, n);
88 return (s1);
91 void *
92 memchr(const void *sptr, int c1, size_t n)
94 if (n != 0) {
95 unsigned char c = (unsigned char)c1;
96 const unsigned char *sp = sptr;
98 do {
99 if (*sp++ == c)
100 return ((void *)--sp);
101 } while (--n != 0);
103 return (NULL);