]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Concatenation Functions for <string.h>.\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are licensed and made available under\r | |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | #include <Uefi.h>\r | |
14 | #include <Library/BaseLib.h>\r | |
15 | \r | |
16 | #include <LibConfig.h>\r | |
17 | \r | |
18 | #include <string.h>\r | |
19 | \r | |
20 | /** The strcat function appends a copy of the string pointed to by s2\r | |
21 | (including the terminating null character) to the end of the string pointed\r | |
22 | to by s1. The initial character of s2 overwrites the null character at the\r | |
23 | end of s1. If copying takes place between objects that overlap, the\r | |
24 | behavior is undefined.\r | |
25 | \r | |
26 | @return The strcat function returns the value of s1.\r | |
27 | **/\r | |
28 | char *\r | |
29 | strcat(char * __restrict s1, const char * __restrict s2)\r | |
30 | {\r | |
31 | return AsciiStrCat( s1, s2);\r | |
32 | }\r | |
33 | \r | |
34 | /** The strncat function appends not more than n characters (a null character\r | |
35 | and characters that follow it are not appended) from the array pointed to\r | |
36 | by s2 to the end of the string pointed to by s1. The initial character of\r | |
37 | s2 overwrites the null character at the end of s1. A terminating null\r | |
38 | character is always appended to the result. If copying takes place\r | |
39 | between objects that overlap, the behavior is undefined.\r | |
40 | \r | |
41 | @return The strncat function returns the value of s1.\r | |
42 | **/\r | |
43 | char *\r | |
44 | strncat(char * __restrict s1, const char * __restrict s2, size_t n)\r | |
45 | {\r | |
46 | return AsciiStrnCat( s1, s2, n);\r | |
47 | }\r | |
48 | \r | |
49 | /** The strncatX function appends not more than n characters (a null character\r | |
50 | and characters that follow it are not appended) from the array pointed to\r | |
51 | by s2 to the end of the string pointed to by s1. The initial character of\r | |
52 | s2 overwrites the null character at the end of s1. The result is always\r | |
53 | terminated with a null character. If copying takes place between objects\r | |
54 | that overlap, the behavior is undefined.\r | |
55 | \r | |
56 | strncatX exists because normal strncat does not indicate if the operation\r | |
57 | was terminated because of exhausting n or reaching the end of s2.\r | |
58 | \r | |
59 | @return The strncatX function returns 0 if the operation was terminated\r | |
60 | because it reached the end of s1. Otherwise, a non-zero value is\r | |
61 | returned indicating how many characters remain in s1.\r | |
62 | **/\r | |
63 | int\r | |
64 | strncatX(char * __restrict s1, const char * __restrict s2, size_t n)\r | |
65 | {\r | |
66 | int NumLeft;\r | |
67 | \r | |
68 | // Find s1's terminating NUL\r | |
69 | for( ; n != 0; --n) {\r | |
70 | if( *s1++ == '\0') break;\r | |
71 | }\r | |
72 | \r | |
73 | // Now copy *s2 into s1, overwriting s1's terminating NUL\r | |
74 | for( --s1; n != 0; --n) {\r | |
75 | if((*s1++ = *s2++) == '\0') break;\r | |
76 | }\r | |
77 | NumLeft = (int)n;\r | |
78 | \r | |
79 | // Guarantee that s1 is NUL terminated.\r | |
80 | *--s1 = '\0';\r | |
81 | \r | |
82 | return NumLeft; // Zero if we ran out of buffer ( strlen(s1) < strlen(s2) )\r | |
83 | }\r |