xref: /titanic_41/usr/src/uts/common/krtld/kobj_subr.c (revision fd9cb95cbb2f626355a60efb9d02c5f0a33c10e6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 
32 /*
33  * Standalone copies of some basic routines.
34  */
35 
36 int
37 strcmp(const char *s1, const char *s2)
38 {
39 	if (s1 == s2)
40 		return (0);
41 	while (*s1 == *s2++)
42 		if (*s1++ == '\0')
43 			return (0);
44 	return (*s1 - s2[-1]);
45 }
46 
47 /*
48  * Compare strings (at most n bytes): return *s1-*s2 for the last
49  * characters in s1 and s2 which were compared.
50  */
51 int
52 strncmp(const char *s1, const char *s2, size_t n)
53 {
54 	if (s1 == s2)
55 		return (0);
56 	n++;
57 	while (--n != 0 && *s1 == *s2++)
58 		if (*s1++ == '\0')
59 			return (0);
60 	return ((n == 0) ? 0 : *s1 - *--s2);
61 }
62 
63 size_t
64 strlen(const char *s)
65 {
66 	const char *s0 = s + 1;
67 
68 	while (*s++ != '\0')
69 		;
70 	return (s - s0);
71 }
72 
73 char *
74 strcpy(char *s1, const char *s2)
75 {
76 	char *os1 = s1;
77 
78 	while (*s1++ = *s2++)
79 		;
80 	return (os1);
81 }
82 
83 char *
84 strncpy(char *s1, const char *s2, size_t n)
85 {
86 	char *os1 = s1;
87 
88 	n++;
89 	while ((--n != 0) && ((*s1++ = *s2++) != '\0'))
90 		;
91 	if (n != 0)
92 		while (--n != 0)
93 			*s1++ = '\0';
94 	return (os1);
95 }
96 
97 char *
98 strcat(char *s1, const char *s2)
99 {
100 	char *os1 = s1;
101 
102 	while (*s1++)
103 		;
104 	--s1;
105 	while (*s1++ = *s2++)
106 		;
107 	return (os1);
108 }
109 
110 char *
111 strchr(const char *sp, int c)
112 {
113 
114 	do {
115 		if (*sp == (char)c)
116 			return ((char *)sp);
117 	} while (*sp++);
118 	return (NULL);
119 }
120 
121 void
122 bzero(void *p_arg, size_t count)
123 {
124 	char zero = 0;
125 	caddr_t p = p_arg;
126 
127 	while (count != 0)
128 		*p++ = zero, count--;	/* Avoid clr for 68000, still... */
129 }
130 
131 void
132 bcopy(const void *src_arg, void *dest_arg, size_t count)
133 {
134 	caddr_t src = (caddr_t)src_arg;
135 	caddr_t dest = dest_arg;
136 
137 	if (src < dest && (src + count) > dest) {
138 		/* overlap copy */
139 		while (--count != -1)
140 			*(dest + count) = *(src + count);
141 	} else {
142 		while (--count != -1)
143 			*dest++ = *src++;
144 	}
145 }
146