]> git.proxmox.com Git - efi-boot-shim.git/blob - ucs2.h
MokManager: enhance the password prompt
[efi-boot-shim.git] / ucs2.h
1 /*
2 * shim - trivial UEFI first-stage bootloader
3 *
4 * Copyright 2013 Red Hat, Inc <pjones@redhat.com>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Significant portions of this code are derived from Tianocore
32 * (http://tianocore.sf.net) and are Copyright 2009-2012 Intel
33 * Corporation.
34 */
35
36 #ifndef SHIM_UCS2_H
37 #define SHIM_UCS2_H
38
39 static inline INTN
40 __attribute__((unused))
41 StrCaseCmp(CHAR16 *s0, CHAR16 *s1)
42 {
43 CHAR16 c0, c1;
44 while (1) {
45 if (*s0 == L'\0' || *s1 == L'\0')
46 return *s1 - *s0;
47 c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0;
48 c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1;
49 if (c0 != c1)
50 return c1 - c0;
51 s0++;
52 s1++;
53 }
54 return 0;
55 }
56
57 static inline INTN
58 __attribute__((unused))
59 StrnCaseCmp(CHAR16 *s0, CHAR16 *s1, int n)
60 {
61 CHAR16 c0, c1;
62 int x = 0;
63 while (n > x++) {
64 if (*s0 == L'\0' || *s1 == L'\0')
65 return *s1 - *s0;
66 c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0;
67 c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1;
68 if (c0 != c1)
69 return c1 - c0;
70 s0++;
71 s1++;
72 }
73 return 0;
74 }
75
76 static inline UINTN
77 __attribute__((unused))
78 StrCSpn(const CHAR16 *s, const CHAR16 *reject)
79 {
80 UINTN ret;
81
82 for (ret = 0; s[ret] != L'\0'; ret++) {
83 int i;
84 for (i = 0; reject[i] != L'\0'; i++) {
85 if (reject[i] == s[ret])
86 return ret;
87 }
88 }
89 return ret;
90 }
91
92 #endif /* SHIM_UCS2_H */