Debian Codegraph @

Cryptlib/SysCall/BaseStrings.c

raw
1 #include <OpenSslSupport.h>
2
3 CHAR8 *
4 AsciiStrCat(CHAR8 *Destination, const CHAR8 *Source)
5 {
6 UINTN dest_len = strlen((CHAR8 *)Destination);
7 UINTN i;
8
9 for (i = 0; Source[i] != '\0'; i++)
10 Destination[dest_len + i] = Source[i];
11 Destination[dest_len + i] = '\0';
12
13 return Destination;
14 }
15
16 CHAR8 *
17 AsciiStrCpy(CHAR8 *Destination, const CHAR8 *Source)
18 {
19 UINTN i;
20
21 for (i=0; Source[i] != '\0'; i++)
22 Destination[i] = Source[i];
23 Destination[i] = '\0';
24
25 return Destination;
26 }
27
28 CHAR8 *
29 AsciiStrnCpy(CHAR8 *Destination, const CHAR8 *Source, UINTN count)
30 {
31 UINTN i;
32
33 for (i=0; i < count && Source[i] != '\0'; i++)
34 Destination[i] = Source[i];
35 for ( ; i < count; i++)
36 Destination[i] = '\0';
37
38 return Destination;
39 }
40
41 CHAR8 *
42 ScanMem8(CHAR8 *str, UINTN count, CHAR8 ch)
43 {
44 UINTN i;
45
46 for (i = 0; i < count; i++) {
47 if (str[i] == ch)
48 return str + i;
49 }
50 return NULL;
51 }
52
53 UINT32
54 WriteUnaligned32(UINT32 *Buffer, UINT32 Value)
55 {
56 *Buffer = Value;
57
58 return Value;
59 }
60
61 UINTN
62 AsciiStrSize(const CHAR8 *string)
63 {
64 return strlen(string) + 1;
65 }
66
67 /* Based on AsciiStrDecimalToUintnS() in edk2
68 * MdePkg/Library/BaseLib/SafeString.c */
69 UINTN
70 AsciiStrDecimalToUintn(const CHAR8 *String)
71 {
72 UINTN Result;
73
74 if (String == NULL)
75 return 0;
76
77 /* Ignore the pad spaces (space or tab) */
78 while ((*String == ' ') || (*String == '\t')) {
79 String++;
80 }
81
82 /* Ignore leading Zeros after the spaces */
83 while (*String == '0') {
84 String++;
85 }
86
87 Result = 0;
88
89 while (*String >= '0' && *String <= '9') {
90 Result = Result * 10 + (*String - '0');
91 String++;
92 }
93
94 return Result;
95 }