1 /** @file
2   Language related HII Library implementation.
3 
4   Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 
16 #include "InternalHiiLib.h"
17 
18 /**
19   Retrieves a pointer to the a Null-terminated ASCII string containing the list
20   of languages that an HII handle in the HII Database supports.  The returned
21   string is allocated using AllocatePool().  The caller is responsible for freeing
22   the returned string using FreePool().  The format of the returned string follows
23   the language format assumed the HII Database.
24 
25   If HiiHandle is NULL, then ASSERT().
26 
27   @param[in]  HiiHandle  A handle that was previously registered in the HII Database.
28 
29   @retval NULL   HiiHandle is not registered in the HII database
30   @retval NULL   There are not enough resources available to retrieve the suported
31                  languages.
32   @retval NULL   The list of suported languages could not be retrieved.
33   @retval Other  A pointer to the Null-terminated ASCII string of supported languages.
34 
35 **/
36 CHAR8 *
37 EFIAPI
HiiGetSupportedLanguages(IN EFI_HII_HANDLE HiiHandle)38 HiiGetSupportedLanguages (
39   IN EFI_HII_HANDLE           HiiHandle
40   )
41 {
42   EFI_STATUS  Status;
43   UINTN       LanguageSize;
44   CHAR8       TempSupportedLanguages;
45   CHAR8       *SupportedLanguages;
46 
47   ASSERT (HiiHandle != NULL);
48 
49   //
50   // Retrieve the size required for the supported languages buffer.
51   //
52   LanguageSize = 0;
53   Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);
54 
55   //
56   // If GetLanguages() returns EFI_SUCCESS for a zero size,
57   // then there are no supported languages registered for HiiHandle.  If GetLanguages()
58   // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
59   // in the HII Database
60   //
61   if (Status != EFI_BUFFER_TOO_SMALL) {
62     //
63     // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
64     //
65     return NULL;
66   }
67 
68   //
69   // Allocate the supported languages buffer.
70   //
71   SupportedLanguages = AllocateZeroPool (LanguageSize);
72   if (SupportedLanguages == NULL) {
73     //
74     // Return NULL if allocation fails.
75     //
76     return NULL;
77   }
78 
79   //
80   // Retrieve the supported languages string
81   //
82   Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);
83   if (EFI_ERROR (Status)) {
84     //
85     // Free the buffer and return NULL if the supported languages can not be retrieved.
86     //
87     FreePool (SupportedLanguages);
88     return NULL;
89   }
90 
91   //
92   // Return the Null-terminated ASCII string of supported languages
93   //
94   return SupportedLanguages;
95 }
96 
97