]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
1 /** @file
2 Language related HII Library implementation.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10 #include "InternalHiiLib.h"
11
12 /**
13 Retrieves a pointer to the a Null-terminated ASCII string containing the list
14 of languages that an HII handle in the HII Database supports. The returned
15 string is allocated using AllocatePool(). The caller is responsible for freeing
16 the returned string using FreePool(). The format of the returned string follows
17 the language format assumed the HII Database.
18
19 If HiiHandle is NULL, then ASSERT().
20
21 @param[in] HiiHandle A handle that was previously registered in the HII Database.
22
23 @retval NULL HiiHandle is not registered in the HII database
24 @retval NULL There are not enough resources available to retrieve the supported
25 languages.
26 @retval NULL The list of supported languages could not be retrieved.
27 @retval Other A pointer to the Null-terminated ASCII string of supported languages.
28
29 **/
30 CHAR8 *
31 EFIAPI
32 HiiGetSupportedLanguages (
33 IN EFI_HII_HANDLE HiiHandle
34 )
35 {
36 EFI_STATUS Status;
37 UINTN LanguageSize;
38 CHAR8 TempSupportedLanguages;
39 CHAR8 *SupportedLanguages;
40
41 ASSERT (HiiHandle != NULL);
42
43 //
44 // Retrieve the size required for the supported languages buffer.
45 //
46 LanguageSize = 0;
47 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);
48
49 //
50 // If GetLanguages() returns EFI_SUCCESS for a zero size,
51 // then there are no supported languages registered for HiiHandle. If GetLanguages()
52 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
53 // in the HII Database
54 //
55 if (Status != EFI_BUFFER_TOO_SMALL) {
56 //
57 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
58 //
59 return NULL;
60 }
61
62 //
63 // Allocate the supported languages buffer.
64 //
65 SupportedLanguages = AllocateZeroPool (LanguageSize);
66 if (SupportedLanguages == NULL) {
67 //
68 // Return NULL if allocation fails.
69 //
70 return NULL;
71 }
72
73 //
74 // Retrieve the supported languages string
75 //
76 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);
77 if (EFI_ERROR (Status)) {
78 //
79 // Free the buffer and return NULL if the supported languages can not be retrieved.
80 //
81 FreePool (SupportedLanguages);
82 return NULL;
83 }
84
85 //
86 // Return the Null-terminated ASCII string of supported languages
87 //
88 return SupportedLanguages;
89 }
90