]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Miscellaneous 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 <sys/EfiCdefs.h>\r | |
14 | \r | |
15 | #include <Uefi.h>\r | |
16 | #include <Library/BaseLib.h>\r | |
17 | #include <Library/BaseMemoryLib.h>\r | |
18 | #include <Library/PcdLib.h>\r | |
19 | #include <Library/PrintLib.h>\r | |
20 | \r | |
21 | #include <LibConfig.h>\r | |
22 | \r | |
23 | #include <errno.h>\r | |
24 | #include <limits.h>\r | |
25 | #include <string.h>\r | |
26 | \r | |
27 | extern char *sys_errlist[];\r | |
28 | \r | |
29 | /** The memset function copies the value of c (converted to an unsigned char)\r | |
30 | into each of the first n characters of the object pointed to by s.\r | |
31 | \r | |
32 | @return The memset function returns the value of s.\r | |
33 | **/\r | |
34 | void *\r | |
35 | memset(void *s, int c, size_t n)\r | |
36 | {\r | |
37 | return SetMem( s, (UINTN)n, (UINT8)c);\r | |
38 | }\r | |
39 | \r | |
40 | int\r | |
41 | strerror_r(int errnum, char *buf, size_t buflen)\r | |
42 | {\r | |
43 | const char *estring;\r | |
44 | INTN i;\r | |
45 | int retval = 0;\r | |
46 | \r | |
47 | if( (errnum < 0) || (errnum >= EMAXERRORVAL)) {\r | |
48 | (void) AsciiSPrint( buf, ASCII_STRING_MAX, "Unknown Error: %d.", errnum);\r | |
49 | retval = EINVAL;\r | |
50 | }\r | |
51 | else {\r | |
52 | estring = sys_errlist[errnum];\r | |
53 | for( i = buflen; i > 0; --i) {\r | |
54 | if( (*buf++ = *estring++) == '\0') {\r | |
55 | break;\r | |
56 | }\r | |
57 | }\r | |
58 | if(i == 0) {\r | |
59 | retval = ERANGE;\r | |
60 | }\r | |
61 | }\r | |
62 | return retval;\r | |
63 | }\r | |
64 | \r | |
65 | /** The strerror function maps the number in errnum to a message string.\r | |
66 | Typically, the values for errnum come from errno, but strerror shall map\r | |
67 | any value of type int to a message.\r | |
68 | \r | |
69 | The implementation shall behave as if no library function calls the\r | |
70 | strerror function.\r | |
71 | \r | |
72 | @return The strerror function returns a pointer to the string, the\r | |
73 | contents of which are locale specific. The array pointed to\r | |
74 | shall not be modified by the program, but may be overwritten by\r | |
75 | a subsequent call to the strerror function.\r | |
76 | **/\r | |
77 | char *\r | |
78 | strerror(int errnum)\r | |
79 | {\r | |
80 | static char errorbuf[ASCII_STRING_MAX];\r | |
81 | int status;\r | |
82 | \r | |
83 | status = strerror_r(errnum, errorbuf, sizeof(errorbuf));\r | |
84 | if(status != 0) {\r | |
85 | errno = status;\r | |
86 | }\r | |
87 | return errorbuf;\r | |
88 | }\r | |
89 | \r | |
90 | /** The strlen function computes the length of the string pointed to by s.\r | |
91 | \r | |
92 | @return The strlen function returns the number of characters that\r | |
93 | precede the terminating null character.\r | |
94 | **/\r | |
95 | size_t\r | |
96 | strlen(const char *s)\r | |
97 | {\r | |
98 | return (size_t)AsciiStrLen( s);\r | |
99 | }\r |