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