]>
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 | |
43 | return (int)AsciiStriCmp( s1, s2);\r | |
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 | |
75 | /** The strxfrm function transforms the string pointed to by s2 and places the\r | |
76 | resulting string into the array pointed to by s1. The transformation is\r | |
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 | |
80 | strings. No more than n characters are placed into the resulting array\r | |
81 | pointed to by s1, including the terminating null character. If n is zero,\r | |
82 | s1 is permitted to be a null pointer. If copying takes place between\r | |
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 | |
87 | returned is n or more, the contents of the array pointed to by s1\r | |
88 | are indeterminate.\r | |
89 | **/\r | |
90 | size_t strxfrm(char * __restrict s1, const char * __restrict s2, size_t n)\r | |
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 | |
97 | srclen = strlen(s2);\r | |
98 | if (n != 0) {\r | |
99 | copysize = srclen < n ? srclen : n - 1;\r | |
100 | (void)memcpy(s1, s2, copysize);\r | |
101 | s1[copysize] = 0;\r | |
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 | |
110 | const unsigned char *us1 = (const unsigned char *)s1,\r | |
111 | *us2 = (const unsigned char *)s2;\r | |
d7ce7006 | 112 | int Difference;\r |
2aa62f2b | 113 | \r |
d7ce7006 | 114 | while ( 0 == ( Difference = tolower(*us1) - tolower(*us2))) {\r |
115 | if (*us1 == 0) {\r | |
2aa62f2b | 116 | return (0);\r |
d7ce7006 | 117 | }\r |
118 | us1 += 1;\r | |
119 | us2 += 1;\r | |
120 | }\r | |
121 | return Difference;\r | |
2aa62f2b | 122 | }\r |
123 | \r |