ReactOS  0.4.14-dev-114-gc8cbd56
infhostgen.c File Reference
#include "inflib.h"
#include "infhost.h"
#include <debug.h>
Include dependency graph for infhostgen.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

int InfHostOpenBufferedFile (PHINF InfHandle, void *Buffer, ULONG BufferSize, LANGID LanguageId, ULONG *ErrorLine)
 
int InfHostOpenFile (PHINF InfHandle, const CHAR *FileName, LANGID LanguageId, ULONG *ErrorLine)
 
void InfHostCloseFile (HINF InfHandle)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file infhostgen.c.

Function Documentation

◆ InfHostCloseFile()

void InfHostCloseFile ( HINF  InfHandle)

Definition at line 283 of file infhostgen.c.

284 {
286 
287  Cache = (PINFCACHE)InfHandle;
288 
289  if (Cache == NULL)
290  {
291  return;
292  }
293 
294  while (Cache->FirstSection != NULL)
295  {
296  Cache->FirstSection = InfpFreeSection(Cache->FirstSection);
297  }
298  Cache->LastSection = NULL;
299 
300  FREE(Cache);
301 }
Definition: fatfs.h:173
smooth NULL
Definition: ftsmooth.c:416
struct _INFCACHE * PINFCACHE
PINFCACHESECTION InfpFreeSection(PINFCACHESECTION Section)
Definition: infcore.c:119
#define FREE(ptr, size)
Definition: auth_des.c:64

Referenced by ImportRegistryFile().

◆ InfHostOpenBufferedFile()

int InfHostOpenBufferedFile ( PHINF  InfHandle,
void Buffer,
ULONG  BufferSize,
LANGID  LanguageId,
ULONG ErrorLine 
)

Definition at line 20 of file infhostgen.c.

25 {
28  WCHAR *FileBuffer;
29  ULONG FileBufferSize;
30 
31  *InfHandle = NULL;
32  *ErrorLine = (ULONG)-1;
33 
34  /* Allocate file buffer */
35  FileBufferSize = BufferSize + 2;
36  FileBuffer = MALLOC(FileBufferSize);
37  if (FileBuffer == NULL)
38  {
39  DPRINT1("MALLOC() failed\n");
41  }
42 
43  MEMCPY(FileBuffer, Buffer, BufferSize);
44 
45  /* Append string terminator */
46  FileBuffer[BufferSize] = 0;
47  FileBuffer[BufferSize + 1] = 0;
48 
49  /* Allocate infcache header */
50  Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
51  if (Cache == NULL)
52  {
53  DPRINT1("MALLOC() failed\n");
54  FREE(FileBuffer);
56  }
57 
58  /* Initialize inicache header */
60  sizeof(INFCACHE));
61 
62  Cache->LanguageId = LanguageId;
63 
64  /* Parse the inf buffer */
65  if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferSize, NULL))
66  {
67 // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
68  WCHAR *new_buff;
69 // UINT codepage = CP_ACP;
70  UINT offset = 0;
71 
72 // if (BufferSize > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
73 // {
74 // codepage = CP_UTF8;
75 // offset = sizeof(utf8_bom);
76 // }
77 
78  new_buff = MALLOC(FileBufferSize * sizeof(WCHAR));
79  if (new_buff != NULL)
80  {
81  ULONG len;
82  Status = RtlMultiByteToUnicodeN(new_buff,
83  FileBufferSize * sizeof(WCHAR),
84  &len,
85  (char *)FileBuffer + offset,
86  FileBufferSize - offset);
87 
89  new_buff,
90  new_buff + len / sizeof(WCHAR),
91  ErrorLine);
92  FREE(new_buff);
93  }
94  else
96  }
97  else
98  {
99  WCHAR *new_buff = (WCHAR *)FileBuffer;
100  /* UCS-16 files should start with the Unicode BOM; we should skip it */
101  if (*new_buff == 0xfeff)
102  {
103  new_buff++;
104  FileBufferSize -= sizeof(WCHAR);
105  }
107  new_buff,
108  (WCHAR*)((char*)new_buff + FileBufferSize),
109  ErrorLine);
110  }
111 
112  if (!INF_SUCCESS(Status))
113  {
114  FREE(Cache);
115  Cache = NULL;
116  }
117 
118  /* Free file buffer */
119  FREE(FileBuffer);
120 
121  *InfHandle = (HINF)Cache;
122 
123  return INF_SUCCESS(Status) ? 0 : -1;
124 }
#define INF_SUCCESS(x)
Definition: builddep.h:82
#define MALLOC(Size)
Definition: builddep.h:73
Definition: fatfs.h:173
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD)
#define INF_STATUS_INSUFFICIENT_RESOURCES
Definition: infpriv.h:15
GLintptr offset
Definition: glext.h:5920
PVOID HINF
Definition: infsupp.h:21
int INFSTATUS
Definition: infpriv.h:77
int32_t INT
Definition: typedefs.h:56
NTSYSAPI BOOLEAN NTAPI RtlIsTextUnicode(_In_ CONST VOID *Buffer, _In_ INT Size, _Inout_opt_ INT *Flags)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
struct _INFCACHE * PINFCACHE
#define BufferSize
Definition: classpnp.h:419
#define FREE(ptr, size)
Definition: auth_des.c:64
GLenum GLsizei len
Definition: glext.h:6722
Status
Definition: gdiplustypes.h:24
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
static BOOLEAN InfpParseBuffer(PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
Definition: inffile.c:878
#define ZEROMEMORY(Area, Size)
Definition: builddep.h:74

◆ InfHostOpenFile()

int InfHostOpenFile ( PHINF  InfHandle,
const CHAR FileName,
LANGID  LanguageId,
ULONG ErrorLine 
)

Definition at line 128 of file infhostgen.c.

132 {
133  FILE *File;
134  CHAR *FileBuffer;
136  ULONG FileBufferLength;
139 
140  *InfHandle = NULL;
141  *ErrorLine = (ULONG)-1;
142 
143  /* Open the inf file */
144  File = fopen(FileName, "rb");
145  if (NULL == File)
146  {
147  DPRINT1("fopen() failed (errno %d)\n", errno);
148  return -1;
149  }
150 
151  DPRINT("fopen() successful\n");
152 
153  /* Query file size */
154  if (fseek(File, (size_t)0, SEEK_END))
155  {
156  DPRINT1("fseek() to EOF failed (errno %d)\n", errno);
157  fclose(File);
158  return -1;
159  }
160 
162  if ((ULONG) -1 == FileLength)
163  {
164  DPRINT1("ftell() failed (errno %d)\n", errno);
165  fclose(File);
166  return -1;
167  }
168  DPRINT("File size: %u\n", (UINT)FileLength);
169 
170  /* Rewind */
171  if (fseek(File, (size_t)0, SEEK_SET))
172  {
173  DPRINT1("fseek() to BOF failed (errno %d)\n", errno);
174  fclose(File);
175  return -1;
176  }
177 
178  /* Allocate file buffer */
179  FileBufferLength = FileLength + 2;
180  FileBuffer = MALLOC(FileBufferLength);
181  if (FileBuffer == NULL)
182  {
183  DPRINT1("MALLOC() failed\n");
184  fclose(File);
185  return -1;
186  }
187 
188  /* Read file */
189  if (FileLength != fread(FileBuffer, (size_t)1, (size_t)FileLength, File))
190  {
191  DPRINT1("fread() failed (errno %d)\n", errno);
192  FREE(FileBuffer);
193  fclose(File);
194  return -1;
195  }
196 
197  fclose(File);
198 
199  /* Append string terminator */
200  FileBuffer[FileLength] = 0;
201  FileBuffer[FileLength + 1] = 0;
202 
203  /* Allocate infcache header */
204  Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
205  if (Cache == NULL)
206  {
207  DPRINT1("MALLOC() failed\n");
208  FREE(FileBuffer);
209  return -1;
210  }
211 
212  /* Initialize inicache header */
214  sizeof(INFCACHE));
215 
216  Cache->LanguageId = LanguageId;
217 
218  /* Parse the inf buffer */
219  if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferLength, NULL))
220  {
221 // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
222  WCHAR *new_buff;
223 // UINT codepage = CP_ACP;
224  UINT offset = 0;
225 
226 // if (FileLength > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
227 // {
228 // codepage = CP_UTF8;
229 // offset = sizeof(utf8_bom);
230 // }
231 
232  new_buff = MALLOC(FileBufferLength * sizeof(WCHAR));
233  if (new_buff != NULL)
234  {
235  ULONG len;
236  Status = RtlMultiByteToUnicodeN(new_buff,
237  FileBufferLength * sizeof(WCHAR),
238  &len,
239  (char *)FileBuffer + offset,
240  FileBufferLength - offset);
241 
243  new_buff,
244  new_buff + len / sizeof(WCHAR),
245  ErrorLine);
246 
247  FREE(new_buff);
248  }
249  else
251  }
252  else
253  {
254  WCHAR *new_buff = (WCHAR *)FileBuffer;
255  /* UCS-16 files should start with the Unicode BOM; we should skip it */
256  if (*new_buff == 0xfeff)
257  {
258  new_buff++;
259  FileBufferLength -= sizeof(WCHAR);
260  }
262  new_buff,
263  (WCHAR*)((char*)new_buff + FileBufferLength),
264  ErrorLine);
265  }
266 
267  if (!INF_SUCCESS(Status))
268  {
269  FREE(Cache);
270  Cache = NULL;
271  }
272 
273  /* Free file buffer */
274  FREE(FileBuffer);
275 
276  *InfHandle = (HINF)Cache;
277 
278  return INF_SUCCESS(Status) ? 0 : -1;
279 }
#define INF_SUCCESS(x)
Definition: builddep.h:82
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3227
#define MALLOC(Size)
Definition: builddep.h:73
Definition: fatfs.h:173
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD)
char CHAR
Definition: xmlstorage.h:175
#define INF_STATUS_INSUFFICIENT_RESOURCES
Definition: infpriv.h:15
GLintptr offset
Definition: glext.h:5920
int errno
PVOID HINF
Definition: infsupp.h:21
int INFSTATUS
Definition: infpriv.h:77
int32_t INT
Definition: typedefs.h:56
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
NTSYSAPI BOOLEAN NTAPI RtlIsTextUnicode(_In_ CONST VOID *Buffer, _In_ INT Size, _Inout_opt_ INT *Flags)
_In_opt_ PVOID _In_ PCSTR File
Definition: iofuncs.h:615
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
void DPRINT(...)
Definition: polytest.cpp:61
#define SEEK_SET
Definition: jmemansi.c:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _INFCACHE * PINFCACHE
#define FREE(ptr, size)
Definition: auth_des.c:64
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
Status
Definition: gdiplustypes.h:24
#define INF_STATUS_SUCCESS
Definition: builddep.h:77
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
unsigned int ULONG
Definition: retypes.h:1
#define SEEK_END
Definition: cabinet.c:27
Definition: File.h:15
static BOOLEAN InfpParseBuffer(PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
Definition: inffile.c:878
#define ZEROMEMORY(Area, Size)
Definition: builddep.h:74

Referenced by ImportRegistryFile().