]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/PlatformBdsDxe/Generic/String.c
String.h confuse cl.exe. Its name collide with MS's std library.
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / String.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 string.c
15
16 Abstract:
17
18 String support
19
20 Revision History
21
22 --*/
23
24 //
25 // Include common header file for this module.
26 //
27 #include "CommonHeader.h"
28
29 #include "Bds.h"
30 #include "BdsString.h"
31 #include "Language.h"
32
33 EFI_GUID gBdsStringPackGuid = { 0x7bac95d3, 0xddf, 0x42f3, 0x9e, 0x24, 0x7c, 0x64, 0x49, 0x40, 0x37, 0x9a };
34 extern UINT8 PlatformBdsStrings[];
35
36 EFI_STATUS
37 InitializeStringSupport (
38 VOID
39 )
40 /*++
41
42 Routine Description:
43
44 Initialize HII global accessor for string support
45
46 Arguments:
47 None
48
49 Returns:
50 String from ID.
51
52 --*/
53 {
54 EFI_STATUS Status;
55 EFI_HII_PACKAGES *PackageList;
56 //
57 // There should only ever be one HII protocol
58 //
59 Status = gBS->LocateProtocol (
60 &gEfiHiiProtocolGuid,
61 NULL,
62 &Hii
63 );
64 if (!EFI_ERROR (Status)) {
65 PackageList = PreparePackages (1, &gBdsStringPackGuid, PlatformBdsStrings);
66 Status = Hii->NewPack (Hii, PackageList, &gStringPackHandle);
67 FreePool (PackageList);
68 }
69
70 return Status;
71 }
72
73 CHAR16 *
74 GetStringById (
75 IN STRING_REF Id
76 )
77 /*++
78
79 Routine Description:
80
81 Get string by string id from HII Interface
82
83 Arguments:
84
85 Id - String ID.
86
87 Returns:
88
89 CHAR16 * - String from ID.
90 NULL - If error occurs.
91
92 --*/
93 {
94 CHAR16 *String;
95 UINTN StringLength;
96 EFI_STATUS Status;
97
98 //
99 // Set default string size assumption at no more than 256 bytes
100 //
101 StringLength = 0x100;
102
103 String = AllocateZeroPool (StringLength);
104 if (String == NULL) {
105 //
106 // If this happens, we are oh-so-dead, but return a NULL in any case.
107 //
108 return NULL;
109 }
110 //
111 // Get the current string for the current Language
112 //
113 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
114 if (EFI_ERROR (Status)) {
115 if (Status == EFI_BUFFER_TOO_SMALL) {
116 //
117 // Free the old pool
118 //
119 FreePool (String);
120
121 //
122 // Allocate new pool with correct value
123 //
124 String = AllocatePool (StringLength);
125 ASSERT (String != NULL);
126
127 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
128 if (!EFI_ERROR (Status)) {
129 return String;
130 }
131 }
132
133 return NULL;
134 }
135
136 return String;
137 }