• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 Common library assistance routines.
3 
4 Copyright (c) 2004 - 2014, 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 #ifndef _EFI_COMMON_LIB_H
16 #define _EFI_COMMON_LIB_H
17 
18 #include <Common/UefiBaseTypes.h>
19 #include <Common/BuildVersion.h>
20 #define PRINTED_GUID_BUFFER_SIZE  37  // including null-termination
21 
22 #define MAX_LONG_FILE_PATH 500
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 //
29 // Function declarations
30 //
31 VOID
32 PeiZeroMem (
33   IN VOID   *Buffer,
34   IN UINTN  Size
35   )
36 ;
37 
38 VOID
39 PeiCopyMem (
40   IN VOID   *Destination,
41   IN VOID   *Source,
42   IN UINTN  Length
43   )
44 ;
45 
46 VOID
47 ZeroMem (
48   IN VOID   *Buffer,
49   IN UINTN  Size
50   )
51 ;
52 
53 VOID
54 CopyMem (
55   IN VOID   *Destination,
56   IN VOID   *Source,
57   IN UINTN  Length
58   )
59 ;
60 
61 INTN
62 CompareGuid (
63   IN EFI_GUID     *Guid1,
64   IN EFI_GUID     *Guid2
65   )
66 ;
67 
68 EFI_STATUS
69 GetFileImage (
70   IN CHAR8    *InputFileName,
71   OUT CHAR8   **InputFileImage,
72   OUT UINT32  *BytesRead
73   )
74 ;
75 
76 EFI_STATUS
77 PutFileImage (
78   IN CHAR8    *OutputFileName,
79   IN CHAR8    *OutputFileImage,
80   IN UINT32   BytesToWrite
81   )
82 ;
83 /*++
84 
85 Routine Description:
86 
87   This function opens a file and writes OutputFileImage into the file.
88 
89 Arguments:
90 
91   OutputFileName     The name of the file to write.
92   OutputFileImage    A pointer to the memory buffer.
93   BytesToWrite       The size of the memory buffer.
94 
95 Returns:
96 
97   EFI_SUCCESS              The function completed successfully.
98   EFI_INVALID_PARAMETER    One of the input parameters was invalid.
99   EFI_ABORTED              An error occurred.
100   EFI_OUT_OF_RESOURCES     No resource to complete operations.
101 
102 **/
103 
104 UINT8
105 CalculateChecksum8 (
106   IN UINT8        *Buffer,
107   IN UINTN        Size
108   )
109 ;
110 
111 UINT8
112 CalculateSum8 (
113   IN UINT8        *Buffer,
114   IN UINTN        Size
115   )
116 ;
117 
118 UINT16
119 CalculateChecksum16 (
120   IN UINT16       *Buffer,
121   IN UINTN        Size
122   )
123 ;
124 
125 UINT16
126 CalculateSum16 (
127   IN UINT16       *Buffer,
128   IN UINTN        Size
129   )
130 ;
131 
132 EFI_STATUS
133 PrintGuid (
134   IN EFI_GUID                     *Guid
135   )
136 ;
137 
138 #define PRINTED_GUID_BUFFER_SIZE  37  // including null-termination
139 EFI_STATUS
140 PrintGuidToBuffer (
141   IN EFI_GUID     *Guid,
142   IN OUT UINT8    *Buffer,
143   IN UINT32       BufferLen,
144   IN BOOLEAN      Uppercase
145   )
146 ;
147 
148 CHAR8 *
149 LongFilePath (
150  IN CHAR8 *FileName
151 );
152 /*++
153 
154 Routine Description:
155   Convert FileName to the long file path, which can support larger than 260 length.
156 
157 Arguments:
158   FileName         - FileName.
159 
160 Returns:
161   LongFilePath      A pointer to the converted long file path.
162 
163 --*/
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #define ASSERT(x) assert(x)
170 
171 #ifdef __GNUC__
172 #include <stdio.h>
173 #include <sys/stat.h>
174 #define stricmp strcasecmp
175 #define _stricmp strcasecmp
176 #define strnicmp strncasecmp
177 #define strcmpi strcasecmp
178 size_t _filelength(int fd);
179 #ifndef __CYGWIN__
180 char *strlwr(char *s);
181 #endif
182 #endif
183 
184 //
185 // On windows, mkdir only has one parameter.
186 // On unix, it has two parameters
187 //
188 #if defined(__GNUC__)
189 #define mkdir(dir, perm) mkdir(dir, perm)
190 #else
191 #define mkdir(dir, perm) mkdir(dir)
192 #endif
193 
194 #endif
195