1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #include "strings.h"
26
27 size_t Strlcat(char* dest, const char* src, size_t size)
28 {
29 const char* start = src;
30
31 if (size)
32 {
33 char* end = dest + size - 1;
34
35 while (*dest && dest != end)
36 dest++;
37
38 while (*src && dest != end)
39 *dest++ = *src++;
40
41 *dest = '\0';
42 }
43 mike 1.1
44 while (*src)
45 src++;
46
47 return src - start;
48 }
49
50 size_t Strlcpy(char* dest, const char* src, size_t size)
51 {
52 const char* start = src;
53
54 if (size)
55 {
56 char* end = dest + size - 1;
57
58 while (*src && dest != end)
59 *dest++ = *src++;
60
61 *dest = '\0';
62 }
63
64 mike 1.1 while (*src)
65 src++;
66
67 return src - start;
68 }
69
70 size_t Zlcat(MI_Char* dest, const MI_Char* src, size_t size)
71 {
72 const MI_Char* start = src;
73
74 if (size)
75 {
76 MI_Char* end = dest + size - 1;
77
78 while (*dest && dest != end)
79 dest++;
80
81 while (*src && dest != end)
82 *dest++ = *src++;
83
84 *dest = '\0';
85 mike 1.1 }
86
87 while (*src)
88 src++;
89
90 return src - start;
91 }
92
93 size_t Zlcpy(MI_Char* dest, const MI_Char* src, size_t size)
94 {
95 const MI_Char* start = src;
96
97 if (size)
98 {
99 MI_Char* end = dest + size - 1;
100
101 while (*src && dest != end)
102 *dest++ = *src++;
103
104 *dest = '\0';
105 }
106 mike 1.1
107 while (*src)
108 src++;
109
110 return src - start;
111 }
112
113 size_t ZStrlcat(MI_Char* dest, const char* src, size_t size)
114 {
115 const char* start = src;
116
117 if (size)
118 {
119 MI_Char* end = dest + size - 1;
120
121 while (*dest && dest != end)
122 dest++;
123
124 while (*src && dest != end)
125 *dest++ = *src++;
126
127 mike 1.1 *dest = '\0';
128 }
129
130 while (*src)
131 src++;
132
133 return src - start;
134 }
135
136 size_t ZStrlcpy(MI_Char* dest, const char* src, size_t size)
137 {
138 const char* start = src;
139
140 if (size)
141 {
142 MI_Char* end = dest + size - 1;
143
144 while (*src && dest != end)
145 *dest++ = *src++;
146
147 *dest = '\0';
148 mike 1.1 }
149
150 while (*src)
151 src++;
152
153 return src - start;
154 }
155
|
158 mike 1.1 // The following defines string literals for the numbers 0 through 63. The
159 // first character is the length of the string. The subsequent characters
160 // are the string literal iteslf.
161 static const char* _numberStrings[] =
162 {
163 "\0010",
164 "\0011",
165 "\0012",
166 "\0013",
167 "\0014",
168 "\0015",
169 "\0016",
170 "\0017",
171 "\0018",
172 "\0019",
173 "\00210",
174 "\00211",
175 "\00212",
176 "\00213",
177 "\00214",
178 "\00215",
179 mike 1.1 "\00216",
180 "\00217",
181 "\00218",
182 "\00219",
183 "\00220",
184 "\00221",
185 "\00222",
186 "\00223",
187 "\00224",
188 "\00225",
189 "\00226",
190 "\00227",
191 "\00228",
192 "\00229",
193 "\00230",
194 "\00231",
195 "\00232",
196 "\00233",
197 "\00234",
198 "\00235",
199 "\00236",
200 mike 1.1 "\00237",
201 "\00238",
202 "\00239",
203 "\00240",
204 "\00241",
205 "\00242",
206 "\00243",
207 "\00244",
208 "\00245",
209 "\00246",
210 "\00247",
211 "\00248",
212 "\00249",
213 "\00250",
214 "\00251",
215 "\00252",
216 "\00253",
217 "\00254",
218 "\00255",
219 "\00256",
220 "\00257",
221 mike 1.1 "\00258",
222 "\00259",
223 "\00260",
224 "\00261",
225 "\00262",
226 "\00263",
227 };
228
|