import less(1)
[unleashed/tickless.git] / usr / src / psm / promif / ieee1275 / common / prom_string.c
blob05a39f9eeef6b39a703ff5972382d344c846ea61
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1991-1995, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * The routines are NOT part of the interface, merely internal
31 * utilities which assist in making the interface standalone.
34 #include <sys/promif.h>
35 #include <sys/promimpl.h>
38 * a version of string copy that is bounded
40 char *
41 prom_strncpy(register char *s1, register char *s2, size_t n)
43 register char *os1 = s1;
45 n++;
46 while (--n != 0 && (*s1++ = *s2++) != '\0')
48 if (n != 0)
49 while (--n != 0)
50 *s1++ = '\0';
51 return (os1);
55 * and one that knows no bounds
57 char *
58 prom_strcpy(register char *s1, register char *s2)
60 register char *os1;
62 os1 = s1;
63 while (*s1++ = *s2++)
65 return (os1);
69 * a copy of string compare that is bounded
71 int
72 prom_strncmp(register char *s1, register char *s2, register size_t n)
74 n++;
75 if (s1 == s2)
76 return (0);
77 while (--n != 0 && *s1 == *s2++)
78 if (*s1++ == '\0')
79 return (0);
80 return ((n == 0) ? 0: (*s1 - s2[-1]));
84 * and one that knows no bounds
86 int
87 prom_strcmp(register char *s1, register char *s2)
89 while (*s1 == *s2++)
90 if (*s1++ == '\0')
91 return (0);
92 return (*s1 - *--s2);
96 * finds the length of a succession of non-NULL chars
98 int
99 prom_strlen(register char *s)
101 register int n = 0;
103 while (*s++)
104 n++;
106 return (n);
110 * return the ptr in sp at which the character c last
111 * appears; 0 if not found
113 char *
114 prom_strrchr(register char *sp, register char c)
116 register char *r;
118 for (r = (char *)0; *sp != '\0'; ++sp)
119 if (*sp == c)
120 r = sp;
121 return (r);
125 * Concatenate string s2 to string s1
127 char *
128 prom_strcat(register char *s1, register char *s2)
130 char *os1 = s1;
132 while ((*s1) != '\0')
133 s1++; /* find the end of string s1 */
135 while (*s1++ = *s2++) /* Concatenate s2 */
137 return (os1);
141 * Return the ptr in sp at which the character c first
142 * appears; NULL if not found
144 char *
145 prom_strchr(register const char *sp, register int c)
148 do {
149 if (*sp == (char)c)
150 return ((char *)sp);
151 } while (*sp++);
152 return (NULL);