]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/R8Lib.c
Fix a potential bug that GetLanguages() API may return incorrect languages in a strin...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / R8Lib.c
1 /** @file
2 Implement a utility function named R8_EfiLibCompareLanguage.
3
4 Copyright (c) 2007 - 2008, Intel Corporation
5
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14
15 **/
16
17 #include "HiiDatabase.h"
18
19
20 /**
21 Compare whether two names of languages are identical.
22
23 @param Language1 Name of language 1
24 @param Language2 Name of language 2
25
26 @retval TRUE same
27 @retval FALSE not same
28
29 **/
30 BOOLEAN
31 R8_EfiLibCompareLanguage (
32 IN CHAR8 *Language1,
33 IN CHAR8 *Language2
34 )
35 {
36 //
37 // Porting Guide:
38 // This library interface is simply obsolete.
39 // Include the source code to user code.
40 //
41 UINTN Index;
42
43 for (Index = 0; (Language1[Index] != 0) && (Language2[Index] != 0); Index++) {
44 if (Language1[Index] != Language2[Index]) {
45 return FALSE;
46 }
47 }
48
49 if (((Language1[Index] == 0) && (Language2[Index] == 0)) ||
50 ((Language1[Index] == 0) && (Language2[Index] != ';')) ||
51 ((Language1[Index] == ';') && (Language2[Index] != 0)) ||
52 ((Language1[Index] == ';') && (Language2[Index] != ';'))) {
53 return TRUE;
54 }
55
56 return FALSE;
57 }
58
59
60 /**
61 Determine what is the current language setting. The space reserved for Lang
62 must be at least RFC_3066_ENTRY_SIZE bytes;
63
64 If Lang is NULL, then ASSERT.
65
66 @param Lang Pointer of system language. Lang will always be filled with
67 a valid RFC 3066 language string. If "PlatformLang" is not
68 set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang
69 is returned.
70
71 @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.
72 @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 GetCurrentLanguage (
78 OUT CHAR8 *Lang
79 )
80 {
81 EFI_STATUS Status;
82 UINTN Size;
83
84 ASSERT (Lang != NULL);
85
86 //
87 // Get current language setting
88 //
89 Size = RFC_3066_ENTRY_SIZE;
90 Status = gRT->GetVariable (
91 L"PlatformLang",
92 &gEfiGlobalVariableGuid,
93 NULL,
94 &Size,
95 Lang
96 );
97
98 if (EFI_ERROR (Status)) {
99 AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang));
100 }
101
102 return Status;
103 }
104
105