]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Comparison 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 | #include <Library/BaseMemoryLib.h>\r | |
16 | \r | |
17 | #include <LibConfig.h>\r | |
18 | \r | |
19 | #include <ctype.h>\r | |
20 | #include <string.h>\r | |
21 | \r | |
22 | /** The memcmp function compares the first n characters of the object pointed\r | |
23 | to by s1 to the first n characters of the object pointed to by s2.\r | |
24 | \r | |
25 | @return The memcmp function returns an integer greater than, equal to, or\r | |
26 | less than zero, accordingly as the object pointed to by s1 is\r | |
27 | greater than, equal to, or less than the object pointed to by s2.\r | |
28 | **/\r | |
29 | int memcmp(const void *s1, const void *s2, size_t n)\r | |
30 | {\r | |
31 | return (int)CompareMem( s1, s2, n);\r | |
32 | }\r | |
33 | \r | |
34 | /** The strcmp function compares the string pointed to by s1 to the string\r | |
35 | pointed to by s2.\r | |
36 | \r | |
37 | @return The strcmp function returns an integer greater than, equal to, or\r | |
38 | less than zero, accordingly as the string pointed to by s1 is\r | |
39 | greater than, equal to, or less than the string pointed to by s2.\r | |
40 | **/\r | |
41 | int strcmp(const char *s1, const char *s2)\r | |
42 | {\r | |
eaa52ade | 43 | return (int)AsciiStrCmp( s1, s2);\r |
2aa62f2b | 44 | }\r |
45 | \r | |
46 | /** The strcoll function compares the string pointed to by s1 to the string\r | |
47 | pointed to by s2, both interpreted as appropriate to the LC_COLLATE\r | |
48 | category of the current locale.\r | |
49 | \r | |
50 | @return The strcoll function returns an integer greater than, equal to,\r | |
51 | or less than zero, accordingly as the string pointed to by s1 is\r | |
52 | greater than, equal to, or less than the string pointed to by s2\r | |
53 | when both are interpreted as appropriate to the current locale.\r | |
54 | **/\r | |
55 | int strcoll(const char *s1, const char *s2)\r | |
56 | {\r | |
57 | /* LC_COLLATE is unimplemented, hence always "C" */\r | |
58 | return (strcmp(s1, s2));\r | |
59 | }\r | |
60 | \r | |
61 | /** The strncmp function compares not more than n characters (characters that\r | |
62 | follow a null character are not compared) from the array pointed to by s1\r | |
63 | to the array pointed to by s2.\r | |
64 | \r | |
65 | @return The strncmp function returns an integer greater than, equal to,\r | |
66 | or less than zero, accordingly as the possibly null-terminated\r | |
67 | array pointed to by s1 is greater than, equal to, or less than\r | |
68 | the possibly null-terminated array pointed to by s2.\r | |
69 | **/\r | |
70 | int strncmp(const char *s1, const char *s2, size_t n)\r | |
71 | {\r | |
72 | return (int)AsciiStrnCmp( s1, s2, n);\r | |
73 | }\r | |
74 | \r | |
eaa52ade | 75 | /** The strxfrm function transforms the string pointed to by Src and places the\r |
76 | resulting string into the array pointed to by Dest. The transformation is\r | |
2aa62f2b | 77 | such that if the strcmp function is applied to two transformed strings, it\r |
78 | returns a value greater than, equal to, or less than zero, corresponding to\r | |
79 | the result of the strcoll function applied to the same two original\r | |
eaa52ade | 80 | strings. No more than Len characters are placed into the resulting array\r |
81 | pointed to by Dest, including the terminating null character. If Len is zero,\r | |
82 | Dest is permitted to be a null pointer. If copying takes place between\r | |
2aa62f2b | 83 | objects that overlap, the behavior is undefined.\r |
84 | \r | |
85 | @return The strxfrm function returns the length of the transformed string\r | |
86 | (not including the terminating null character). If the value\r | |
eaa52ade | 87 | returned is Len or more, the contents of the array pointed to by Dest\r |
2aa62f2b | 88 | are indeterminate.\r |
89 | **/\r | |
eaa52ade | 90 | size_t strxfrm(char * __restrict Dest, const char * __restrict Src, size_t Len)\r |
2aa62f2b | 91 | {\r |
92 | size_t srclen, copysize;\r | |
93 | \r | |
94 | /*\r | |
95 | * Since locales are unimplemented, this is just a copy.\r | |
96 | */\r | |
eaa52ade | 97 | srclen = strlen(Src);\r |
98 | if (Len != 0) {\r | |
99 | copysize = srclen < Len ? srclen : Len - 1;\r | |
100 | (void)memcpy(Dest, Src, copysize);\r | |
101 | Dest[copysize] = 0;\r | |
2aa62f2b | 102 | }\r |
103 | return (srclen);\r | |
104 | }\r | |
105 | \r | |
106 | /** Case agnostic string comparison for NetBSD compatibility. **/\r | |
107 | int\r | |
108 | strcasecmp(const char *s1, const char *s2)\r | |
109 | {\r | |
eaa52ade | 110 | return (int)AsciiStriCmp( s1, s2);\r |
2aa62f2b | 111 | }\r |