]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/String/String.c
Removed one useless makefile, and corrected some BSD licenses
[mirror_edk2.git] / Tools / Source / TianoTools / String / String.c
CommitLineData
56fe62ce 1/*++\r
d2ec0d9e 2\r
cf171110 3Copyright (c) 2004-2006 Intel Corporation. All rights reserved\r
56fe62ce 4This program and the accompanying materials are licensed and made available\r
5under the terms and conditions of the BSD License which accompanies this\r
6distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
d2ec0d9e 8\r
56fe62ce 9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
d2ec0d9e 11\r
d2ec0d9e 12\r
56fe62ce 13Module Name:\r
14\r
15 String.c\r
16\r
17Abstract:\r
18\r
19 Unicode and ASCII string primatives.\r
20\r
21--*/\r
d2ec0d9e 22\r
23#include <assert.h>\r
ce53a8c3 24\r
25#include <Common/UefiBaseTypes.h>\r
26\r
27#include "CommonLib.h"\r
d2ec0d9e 28\r
3ce2b1a8 29/**\r
30 Returns the length of a Null-terminated Unicode string.\r
31\r
32 This function returns the number of Unicode characters in the Null-terminated\r
33 Unicode string specified by String.\r
34\r
35 If String is NULL, then ASSERT().\r
36\r
37 @param String Pointer to a Null-terminated Unicode string.\r
38\r
39 @return The length of String.\r
40\r
41**/\r
42UINTN\r
43EFIAPI\r
44StrLen (\r
45 IN CONST CHAR16 *String\r
46 )\r
47{\r
48 UINTN Length;\r
49\r
50 ASSERT (String != NULL);\r
51\r
52 for (Length = 0; *String != L'\0'; String++, Length++) {\r
53 ;\r
54 }\r
55 return Length;\r
56}\r
57\r
58/**\r
59 Returns the length of a Null-terminated ASCII string.\r
60\r
61 This function returns the number of ASCII characters in the Null-terminated\r
62 ASCII string specified by String.\r
63\r
64 If String is NULL, then ASSERT().\r
65\r
66 @param String Pointer to a Null-terminated ASCII string.\r
67\r
68 @return The length of String.\r
69\r
70**/\r
71UINTN\r
72EFIAPI\r
73AsciiStrLen (\r
74 IN CONST CHAR8 *String\r
75 )\r
76{\r
77 UINTN Length;\r
78\r
79 ASSERT (String != NULL);\r
80\r
81 for (Length = 0; *String != '\0'; String++, Length++) {\r
82 ;\r
83 }\r
84 return Length;\r
85}\r
86\r
d2ec0d9e 87/**\r
88 Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
89 string and returns the new Unicode string.\r
90\r
91 This function copies the contents of the Unicode string Source to the Unicode\r
92 string Destination, and returns Destination. If Source and Destination\r
93 overlap, then the results are undefined.\r
94\r
95 If Destination is NULL, then ASSERT().\r
96 If Source is NULL, then ASSERT().\r
97 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 98\r
99 @param Destination Pointer to a Null-terminated Unicode string.\r
100 @param Source Pointer to a Null-terminated Unicode string.\r
101\r
102 @return Destiantion\r
103\r
104**/\r
105CHAR16 *\r
106EFIAPI\r
107StrCpy (\r
108 OUT CHAR16 *Destination,\r
109 IN CONST CHAR16 *Source\r
110 )\r
111{\r
112 CHAR16 *ReturnValue;\r
113\r
114 //\r
115 // Destination cannot be NULL\r
116 //\r
117 ASSERT (Destination != NULL);\r
118\r
119 //\r
120 // Destination and source cannot overlap\r
121 //\r
122 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r
123 ASSERT ((UINTN)(Source - Destination) > StrLen (Source));\r
124\r
125 ReturnValue = Destination;\r
126 while (*Source) {\r
127 *(Destination++) = *(Source++);\r
128 }\r
129 *Destination = 0;\r
130 return ReturnValue;\r
131}\r
132\r
133/**\r
134 Copies one Null-terminated Unicode string with a maximum length to another\r
135 Null-terminated Unicode string with a maximum length and returns the new\r
136 Unicode string.\r
137\r
138 This function copies the contents of the Unicode string Source to the Unicode\r
139 string Destination, and returns Destination. At most, Length Unicode\r
140 characters are copied from Source to Destination. If Length is 0, then\r
141 Destination is returned unmodified. If Length is greater that the number of\r
142 Unicode characters in Source, then Destination is padded with Null Unicode\r
143 characters. If Source and Destination overlap, then the results are\r
144 undefined.\r
145\r
146 If Destination is NULL, then ASSERT().\r
147 If Source is NULL, then ASSERT().\r
148 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 149\r
150 @param Destination Pointer to a Null-terminated Unicode string.\r
151 @param Source Pointer to a Null-terminated Unicode string.\r
152 @param Length Maximum number of Unicode characters to copy.\r
153\r
154 @return Destination\r
155\r
156**/\r
157CHAR16 *\r
158EFIAPI\r
159StrnCpy (\r
160 OUT CHAR16 *Destination,\r
161 IN CONST CHAR16 *Source,\r
162 IN UINTN Length\r
163 )\r
164{\r
165 CHAR16 *ReturnValue;\r
166\r
167 if (Length == 0) {\r
168 return Destination;\r
169 }\r
170\r
171 //\r
172 // Destination cannot be NULL if Length is not zero\r
173 //\r
174 ASSERT (Destination != NULL);\r
175\r
176 //\r
177 // Destination and source cannot overlap\r
178 // Q: Does Source have to be NULL-terminated?\r
179 //\r
180 ASSERT ((UINTN)(Destination - Source) > StrLen (Source));\r
181 ASSERT ((UINTN)(Source - Destination) >= Length);\r
182\r
183 ReturnValue = Destination;\r
184\r
185 while ((*Source != L'\0') && (Length > 0)) {\r
186 *(Destination++) = *(Source++);\r
187 Length--;\r
188 }\r
189\r
d2ec0d9e 190 memset (Destination, 0, Length * sizeof (*Destination));\r
191 return ReturnValue;\r
192}\r
193\r
d2ec0d9e 194/**\r
195 Returns the size of a Null-terminated Unicode string in bytes, including the\r
196 Null terminator.\r
197\r
198 This function returns the size, in bytes, of the Null-terminated Unicode\r
199 string specified by String.\r
200\r
201 If String is NULL, then ASSERT().\r
d2ec0d9e 202\r
203 @param String Pointer to a Null-terminated Unicode string.\r
204\r
205 @return The size of String.\r
206\r
207**/\r
208UINTN\r
209EFIAPI\r
210StrSize (\r
211 IN CONST CHAR16 *String\r
212 )\r
213{\r
214 return (StrLen (String) + 1) * sizeof (*String);\r
215}\r
216\r
217/**\r
218 Compares two Null-terminated Unicode strings, and returns the difference\r
219 between the first mismatched Unicode characters.\r
220\r
221 This function compares the Null-terminated Unicode string FirstString to the\r
222 Null-terminated Unicode string SecondString. If FirstString is identical to\r
223 SecondString, then 0 is returned. Otherwise, the value returned is the first\r
224 mismatched Unicode character in SecondString subtracted from the first\r
225 mismatched Unicode character in FirstString.\r
226\r
227 If FirstString is NULL, then ASSERT().\r
228 If SecondString is NULL, then ASSERT().\r
d2ec0d9e 229\r
230 @param FirstString Pointer to a Null-terminated Unicode string.\r
231 @param SecondString Pointer to a Null-terminated Unicode string.\r
232\r
233 @retval 0 FirstString is identical to SecondString.\r
234 @retval !=0 FirstString is not identical to SecondString.\r
235\r
236**/\r
237INTN\r
238EFIAPI\r
239StrCmp (\r
240 IN CONST CHAR16 *FirstString,\r
241 IN CONST CHAR16 *SecondString\r
242 )\r
243{\r
244 //\r
ce53a8c3 245 // ASSERT both strings should never be zero\r
d2ec0d9e 246 //\r
247 ASSERT (StrSize (FirstString) != 0);\r
248 ASSERT (StrSize (SecondString) != 0);\r
249\r
250 while ((*FirstString != L'\0') && (*FirstString == *SecondString)) {\r
251 FirstString++;\r
252 SecondString++;\r
253 }\r
254 return *FirstString - *SecondString;\r
255}\r
256\r
257/**\r
258 Compares two Null-terminated Unicode strings with maximum lengths, and\r
259 returns the difference between the first mismatched Unicode characters.\r
260\r
261 This function compares the Null-terminated Unicode string FirstString to the\r
262 Null-terminated Unicode string SecondString. At most, Length Unicode\r
263 characters will be compared. If Length is 0, then 0 is returned. If\r
264 FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r
265 value returned is the first mismatched Unicode character in SecondString\r
266 subtracted from the first mismatched Unicode character in FirstString.\r
267\r
268 If FirstString is NULL, then ASSERT().\r
269 If SecondString is NULL, then ASSERT().\r
d2ec0d9e 270\r
271 @param FirstString Pointer to a Null-terminated Unicode string.\r
272 @param SecondString Pointer to a Null-terminated Unicode string.\r
273 @param Length Maximum number of Unicode characters to compare.\r
274\r
275 @retval 0 FirstString is identical to SecondString.\r
276 @retval !=0 FirstString is not identical to SecondString.\r
277\r
278**/\r
279INTN\r
280EFIAPI\r
281StrnCmp (\r
282 IN CONST CHAR16 *FirstString,\r
283 IN CONST CHAR16 *SecondString,\r
284 IN UINTN Length\r
285 )\r
286{\r
287 if (Length == 0) {\r
288 return 0;\r
289 }\r
290\r
291 //\r
ce53a8c3 292 // ASSERT both strings should never be zero\r
d2ec0d9e 293 //\r
294 ASSERT (StrSize (FirstString) != 0);\r
295 ASSERT (StrSize (SecondString) != 0);\r
296\r
297 while ((*FirstString != L'\0') &&\r
298 (*FirstString == *SecondString) &&\r
299 (Length > 1)) {\r
300 FirstString++;\r
301 SecondString++;\r
302 Length--;\r
303 }\r
304\r
305 return *FirstString - *SecondString;\r
306}\r
307\r
308/**\r
309 Concatenates one Null-terminated Unicode string to another Null-terminated\r
310 Unicode string, and returns the concatenated Unicode string.\r
311\r
312 This function concatenates two Null-terminated Unicode strings. The contents\r
313 of Null-terminated Unicode string Source are concatenated to the end of\r
314 Null-terminated Unicode string Destination. The Null-terminated concatenated\r
315 Unicode String is returned. If Source and Destination overlap, then the\r
316 results are undefined.\r
317\r
318 If Destination is NULL, then ASSERT().\r
319 If Source is NULL, then ASSERT().\r
320 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 321\r
322 @param Destination Pointer to a Null-terminated Unicode string.\r
323 @param Source Pointer to a Null-terminated Unicode string.\r
324\r
325 @return Destination\r
326\r
327**/\r
328CHAR16 *\r
329EFIAPI\r
330StrCat (\r
331 IN OUT CHAR16 *Destination,\r
332 IN CONST CHAR16 *Source\r
333 )\r
334{\r
335 StrCpy (Destination + StrLen (Destination), Source);\r
336\r
337 //\r
338 // Size of the resulting string should never be zero.\r
d2ec0d9e 339 //\r
340 ASSERT (StrSize (Destination) != 0);\r
341 return Destination;\r
342}\r
343\r
344/**\r
345 Concatenates one Null-terminated Unicode string with a maximum length to the\r
346 end of another Null-terminated Unicode string, and returns the concatenated\r
347 Unicode string.\r
348\r
349 This function concatenates two Null-terminated Unicode strings. The contents\r
350 of Null-terminated Unicode string Source are concatenated to the end of\r
351 Null-terminated Unicode string Destination, and Destination is returned. At\r
352 most, Length Unicode characters are concatenated from Source to the end of\r
353 Destination, and Destination is always Null-terminated. If Length is 0, then\r
354 Destination is returned unmodified. If Source and Destination overlap, then\r
355 the results are undefined.\r
356\r
357 If Destination is NULL, then ASSERT().\r
358 If Source is NULL, then ASSERT().\r
359 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 360\r
361 @param Destination Pointer to a Null-terminated Unicode string.\r
362 @param Source Pointer to a Null-terminated Unicode string.\r
363 @param Length Maximum number of Unicode characters to concatenate from\r
364 Source.\r
365\r
366 @return Destination\r
367\r
368**/\r
369CHAR16 *\r
370EFIAPI\r
371StrnCat (\r
372 IN OUT CHAR16 *Destination,\r
373 IN CONST CHAR16 *Source,\r
374 IN UINTN Length\r
375 )\r
376{\r
377 StrnCpy (Destination + StrLen (Destination), Source, Length);\r
378\r
379 //\r
380 // Size of the resulting string should never be zero.\r
d2ec0d9e 381 //\r
382 ASSERT (StrSize (Destination) != 0);\r
383 return Destination;\r
384}\r
385\r
386/**\r
387 Copies one Null-terminated ASCII string to another Null-terminated ASCII\r
388 string and returns the new ASCII string.\r
389\r
390 This function copies the contents of the ASCII string Source to the ASCII\r
391 string Destination, and returns Destination. If Source and Destination\r
392 overlap, then the results are undefined.\r
393\r
394 If Destination is NULL, then ASSERT().\r
395 If Source is NULL, then ASSERT().\r
396 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 397\r
398 @param Destination Pointer to a Null-terminated ASCII string.\r
399 @param Source Pointer to a Null-terminated ASCII string.\r
400\r
401 @return Destination\r
402\r
403**/\r
404CHAR8 *\r
405EFIAPI\r
406AsciiStrCpy (\r
407 OUT CHAR8 *Destination,\r
408 IN CONST CHAR8 *Source\r
409 )\r
410{\r
411 CHAR8 *ReturnValue;\r
412\r
413 //\r
414 // Destination cannot be NULL\r
415 //\r
416 ASSERT (Destination != NULL);\r
417\r
418 //\r
419 // Destination and source cannot overlap\r
420 //\r
421 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r
422 ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source));\r
423\r
424 ReturnValue = Destination;\r
425 while (*Source) {\r
426 *(Destination++) = *(Source++);\r
427 }\r
428 *Destination = 0;\r
429 return ReturnValue;\r
430}\r
431\r
432/**\r
433 Copies one Null-terminated ASCII string with a maximum length to another\r
434 Null-terminated ASCII string with a maximum length and returns the new ASCII\r
435 string.\r
436\r
437 This function copies the contents of the ASCII string Source to the ASCII\r
438 string Destination, and returns Destination. At most, Length ASCII characters\r
439 are copied from Source to Destination. If Length is 0, then Destination is\r
440 returned unmodified. If Length is greater that the number of ASCII characters\r
441 in Source, then Destination is padded with Null ASCII characters. If Source\r
442 and Destination overlap, then the results are undefined.\r
443\r
444 If Destination is NULL, then ASSERT().\r
445 If Source is NULL, then ASSERT().\r
446 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 447\r
448 @param Destination Pointer to a Null-terminated ASCII string.\r
449 @param Source Pointer to a Null-terminated ASCII string.\r
450 @param Length Maximum number of ASCII characters to copy.\r
451\r
452 @return Destination\r
453\r
454**/\r
455CHAR8 *\r
456EFIAPI\r
457AsciiStrnCpy (\r
458 OUT CHAR8 *Destination,\r
459 IN CONST CHAR8 *Source,\r
460 IN UINTN Length\r
461 )\r
462{\r
463 CHAR8 *ReturnValue;\r
464\r
465 if (Length == 0) {\r
466 return Destination;\r
467 }\r
468\r
469 //\r
470 // Destination cannot be NULL\r
471 //\r
472 ASSERT (Destination != NULL);\r
473\r
474 //\r
475 // Destination and source cannot overlap\r
476 //\r
477 ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source));\r
478 ASSERT ((UINTN)(Source - Destination) >= Length);\r
479\r
480 ReturnValue = Destination;\r
481\r
482 while (*Source && Length > 0) {\r
483 *(Destination++) = *(Source++);\r
484 Length--;\r
485 }\r
486\r
487 // ZeroMem (Destination, Length * sizeof (*Destination));\r
488 memset (Destination, 0, Length * sizeof (*Destination));\r
489 return ReturnValue;\r
490}\r
491\r
d2ec0d9e 492/**\r
493 Returns the size of a Null-terminated ASCII string in bytes, including the\r
494 Null terminator.\r
495\r
496 This function returns the size, in bytes, of the Null-terminated ASCII string\r
497 specified by String.\r
498\r
499 If String is NULL, then ASSERT().\r
d2ec0d9e 500\r
501 @param String Pointer to a Null-terminated ASCII string.\r
502\r
503 @return The size of String.\r
504\r
505**/\r
506UINTN\r
507EFIAPI\r
508AsciiStrSize (\r
509 IN CONST CHAR8 *String\r
510 )\r
511{\r
512 return (AsciiStrLen (String) + 1) * sizeof (*String);\r
513}\r
514\r
515/**\r
516 Compares two Null-terminated ASCII strings, and returns the difference\r
517 between the first mismatched ASCII characters.\r
518\r
519 This function compares the Null-terminated ASCII string FirstString to the\r
520 Null-terminated ASCII string SecondString. If FirstString is identical to\r
521 SecondString, then 0 is returned. Otherwise, the value returned is the first\r
522 mismatched ASCII character in SecondString subtracted from the first\r
523 mismatched ASCII character in FirstString.\r
524\r
525 If FirstString is NULL, then ASSERT().\r
526 If SecondString is NULL, then ASSERT().\r
d2ec0d9e 527\r
528 @param FirstString Pointer to a Null-terminated ASCII string.\r
529 @param SecondString Pointer to a Null-terminated ASCII string.\r
530\r
531 @retval 0 FirstString is identical to SecondString.\r
532 @retval !=0 FirstString is not identical to SecondString.\r
533\r
534**/\r
535INTN\r
536EFIAPI\r
537AsciiStrCmp (\r
538 IN CONST CHAR8 *FirstString,\r
539 IN CONST CHAR8 *SecondString\r
540 )\r
541{\r
542 //\r
ce53a8c3 543 // ASSERT both strings should never be zero\r
d2ec0d9e 544 //\r
545 ASSERT (AsciiStrSize (FirstString));\r
546 ASSERT (AsciiStrSize (SecondString));\r
547\r
548 while ((*FirstString != '\0') && (*FirstString == *SecondString)) {\r
549 FirstString++;\r
550 SecondString++;\r
551 }\r
552\r
553 return *FirstString - *SecondString;\r
554}\r
555\r
556STATIC\r
557CHAR8\r
558EFIAPI\r
559AsciiToUpper (\r
560 IN CHAR8 Chr\r
561 )\r
562{\r
563 return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr;\r
564}\r
565\r
566/**\r
567 Performs a case insensitive comparison of two Null-terminated ASCII strings,\r
568 and returns the difference between the first mismatched ASCII characters.\r
569\r
570 This function performs a case insensitive comparison of the Null-terminated\r
571 ASCII string FirstString to the Null-terminated ASCII string SecondString. If\r
572 FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r
573 value returned is the first mismatched lower case ASCII character in\r
574 SecondString subtracted from the first mismatched lower case ASCII character\r
575 in FirstString.\r
576\r
577 If FirstString is NULL, then ASSERT().\r
578 If SecondString is NULL, then ASSERT().\r
d2ec0d9e 579\r
580 @param FirstString Pointer to a Null-terminated ASCII string.\r
581 @param SecondString Pointer to a Null-terminated ASCII string.\r
582\r
583 @retval 0 FirstString is identical to SecondString using case insensitive\r
584 comparisons.\r
585 @retval !=0 FirstString is not identical to SecondString using case\r
586 insensitive comparisons.\r
587\r
588**/\r
589INTN\r
590EFIAPI\r
591AsciiStriCmp (\r
592 IN CONST CHAR8 *FirstString,\r
593 IN CONST CHAR8 *SecondString\r
594 )\r
595{\r
596 //\r
ce53a8c3 597 // ASSERT both strings should never be zero\r
d2ec0d9e 598 //\r
599 ASSERT (AsciiStrSize (FirstString));\r
600 ASSERT (AsciiStrSize (SecondString));\r
601\r
602 while ((*FirstString != '\0') &&\r
603 (AsciiToUpper (*FirstString) == AsciiToUpper (*SecondString))) {\r
604 FirstString++;\r
605 SecondString++;\r
606 }\r
607\r
608 return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString);\r
609}\r
610\r
611/**\r
612 Compares two Null-terminated ASCII strings with maximum lengths, and returns\r
613 the difference between the first mismatched ASCII characters.\r
614\r
615 This function compares the Null-terminated ASCII string FirstString to the\r
616 Null-terminated ASCII string SecondString. At most, Length ASCII characters\r
617 will be compared. If Length is 0, then 0 is returned. If FirstString is\r
618 identical to SecondString, then 0 is returned. Otherwise, the value returned\r
619 is the first mismatched ASCII character in SecondString subtracted from the\r
620 first mismatched ASCII character in FirstString.\r
621\r
622 If FirstString is NULL, then ASSERT().\r
623 If SecondString is NULL, then ASSERT().\r
d2ec0d9e 624\r
625 @param FirstString Pointer to a Null-terminated ASCII string.\r
626 @param SecondString Pointer to a Null-terminated ASCII string.\r
627\r
628 @retval 0 FirstString is identical to SecondString.\r
629 @retval !=0 FirstString is not identical to SecondString.\r
630\r
631**/\r
632INTN\r
633EFIAPI\r
634AsciiStrnCmp (\r
635 IN CONST CHAR8 *FirstString,\r
636 IN CONST CHAR8 *SecondString,\r
637 IN UINTN Length\r
638 )\r
639{\r
640 //\r
ce53a8c3 641 // ASSERT both strings should never be zero\r
d2ec0d9e 642 //\r
643 ASSERT (AsciiStrSize (FirstString));\r
644 ASSERT (AsciiStrSize (SecondString));\r
645\r
646 while ((*FirstString != '\0') &&\r
647 (*FirstString == *SecondString) &&\r
648 (Length > 1)) {\r
649 FirstString++;\r
650 SecondString++;\r
651 Length--;\r
652 }\r
653 return *FirstString - *SecondString;\r
654}\r
655\r
656/**\r
657 Concatenates one Null-terminated ASCII string to another Null-terminated\r
658 ASCII string, and returns the concatenated ASCII string.\r
659\r
660 This function concatenates two Null-terminated ASCII strings. The contents of\r
661 Null-terminated ASCII string Source are concatenated to the end of Null-\r
662 terminated ASCII string Destination. The Null-terminated concatenated ASCII\r
663 String is returned.\r
664\r
665 If Destination is NULL, then ASSERT().\r
666 If Source is NULL, then ASSERT().\r
d2ec0d9e 667\r
668 @param Destination Pointer to a Null-terminated ASCII string.\r
669 @param Source Pointer to a Null-terminated ASCII string.\r
670\r
671 @return Destination\r
672\r
673**/\r
674CHAR8 *\r
675EFIAPI\r
676AsciiStrCat (\r
677 IN OUT CHAR8 *Destination,\r
678 IN CONST CHAR8 *Source\r
679 )\r
680{\r
681 AsciiStrCpy (Destination + AsciiStrLen (Destination), Source);\r
682\r
683 //\r
684 // Size of the resulting string should never be zero.\r
d2ec0d9e 685 //\r
686 ASSERT (AsciiStrSize (Destination) != 0);\r
687 return Destination;\r
688}\r
689\r
690/**\r
691 Concatenates one Null-terminated ASCII string with a maximum length to the\r
692 end of another Null-terminated ASCII string, and returns the concatenated\r
693 ASCII string.\r
694\r
695 This function concatenates two Null-terminated ASCII strings. The contents\r
696 of Null-terminated ASCII string Source are concatenated to the end of Null-\r
697 terminated ASCII string Destination, and Destination is returned. At most,\r
698 Length ASCII characters are concatenated from Source to the end of\r
699 Destination, and Destination is always Null-terminated. If Length is 0, then\r
700 Destination is returned unmodified. If Source and Destination overlap, then\r
701 the results are undefined.\r
702\r
703 If Destination is NULL, then ASSERT().\r
704 If Source is NULL, then ASSERT().\r
705 If Source and Destination overlap, then ASSERT().\r
d2ec0d9e 706\r
707 @param Destination Pointer to a Null-terminated ASCII string.\r
708 @param Source Pointer to a Null-terminated ASCII string.\r
709 @param Length Maximum number of ASCII characters to concatenate from\r
710 Source.\r
711\r
712 @return Destination\r
713\r
714**/\r
715CHAR8 *\r
716EFIAPI\r
717AsciiStrnCat (\r
718 IN OUT CHAR8 *Destination,\r
719 IN CONST CHAR8 *Source,\r
720 IN UINTN Length\r
721 )\r
722{\r
723 AsciiStrnCpy (Destination + AsciiStrLen (Destination), Source, Length);\r
724\r
725 //\r
726 // Size of the resulting string should never be zero.\r
d2ec0d9e 727 //\r
728 ASSERT (AsciiStrSize (Destination) != 0);\r
729 return Destination;\r
730}\r