1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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) 1991-1995, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The routines are NOT part of the interface, merely internal
* utilities which assist in making the interface standalone.
*/
#include <sys/promif.h>
#include <sys/promimpl.h>
/*
* a version of string copy that is bounded
*/
char *
prom_strncpy(register char *s1, register char *s2, size_t n)
{
register char *os1 = s1;
n++;
while (--n != 0 && (*s1++ = *s2++) != '\0')
;
if (n != 0)
while (--n != 0)
*s1++ = '\0';
return (os1);
}
/*
* and one that knows no bounds
*/
char *
prom_strcpy(register char *s1, register char *s2)
{
register char *os1;
os1 = s1;
while (*s1++ = *s2++)
;
return (os1);
}
/*
* a copy of string compare that is bounded
*/
int
prom_strncmp(register char *s1, register char *s2, register size_t n)
{
n++;
if (s1 == s2)
return (0);
while (--n != 0 && *s1 == *s2++)
if (*s1++ == '\0')
return (0);
return ((n == 0) ? 0: (*s1 - s2[-1]));
}
/*
* and one that knows no bounds
*/
int
prom_strcmp(register char *s1, register char *s2)
{
while (*s1 == *s2++)
if (*s1++ == '\0')
return (0);
return (*s1 - *--s2);
}
/*
* finds the length of a succession of non-NULL chars
*/
int
prom_strlen(register char *s)
{
register int n = 0;
while (*s++)
n++;
return (n);
}
/*
* return the ptr in sp at which the character c last
* appears; 0 if not found
*/
char *
prom_strrchr(register char *sp, register char c)
{
register char *r;
for (r = (char *)0; *sp != (char)0; ++sp)
if (*sp == c)
r = sp;
return (r);
}
/*
* Concatenate string s2 to string s1
*/
char *
prom_strcat(register char *s1, register char *s2)
{
char *os1 = s1;
while ((*s1) != ((char)0))
s1++; /* find the end of string s1 */
while (*s1++ = *s2++) /* Concatenate s2 */
;
return (os1);
}
/*
* Return the ptr in sp at which the character c first
* appears; NULL if not found
*/
char *
prom_strchr(register const char *sp, register int c)
{
do {
if (*sp == (char)c)
return ((char *)sp);
} while (*sp++);
return (NULL);
}
|