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