ReactOS  0.4.14-dev-358-gbef841c
infrosput.c
Go to the documentation of this file.
1 /*
2  * PROJECT: .inf file parser
3  * LICENSE: GPL - See COPYING in the top level directory
4  * COPYRIGHT: Copyright 2005 Ge van Geldorp <gvg@reactos.org>
5  */
6 
7 /* INCLUDES *****************************************************************/
8 
9 #include "inflib.h"
10 #include "infros.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
16 InfWriteFile(HINF InfHandle,
18  PUNICODE_STRING HeaderComment)
19 {
24  INFSTATUS InfStatus;
25  PWCHAR Buffer;
27  PWCHAR HeaderBuffer;
28  ULONG HeaderBufferSize;
29  UINT Index;
30 
31  InfStatus = InfpBuildFileBuffer((PINFCACHE) InfHandle, &Buffer, &BufferSize);
32  if (! INF_SUCCESS(InfStatus))
33  {
34  DPRINT("Failed to create buffer (Status 0x%lx)\n", InfStatus);
35  return InfStatus;
36  }
37 
38  /* Open the inf file */
40  FileName,
41  0,
42  NULL,
43  NULL);
44 
49  0,
51  if (!INF_SUCCESS(Status))
52  {
53  DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
54  FREE(Buffer);
55  return Status;
56  }
57 
58  DPRINT("NtOpenFile() successful\n");
59 
60  if (NULL != HeaderComment && 0 != HeaderComment->Length)
61  {
62  /* This is just a comment header, don't abort on errors here */
63  HeaderBufferSize = HeaderComment->Length + 7 * sizeof(WCHAR);
64  HeaderBuffer = MALLOC(HeaderBufferSize);
65  if (NULL != HeaderBuffer)
66  {
67  strcpyW(HeaderBuffer, L"; ");
68  for (Index = 0; Index < HeaderComment->Length / sizeof(WCHAR); Index++)
69  {
70  HeaderBuffer[2 + Index] = HeaderComment->Buffer[Index];
71  }
72  strcpyW(HeaderBuffer + (2 + HeaderComment->Length / sizeof(WCHAR)),
73  L"\r\n\r\n");
75  NULL,
76  NULL,
77  NULL,
79  HeaderBuffer,
80  HeaderBufferSize,
81  NULL,
82  NULL);
83  FREE(HeaderBuffer);
84  }
85  }
86 
87  /* Write main contents */
89  NULL,
90  NULL,
91  NULL,
93  Buffer,
94  BufferSize,
95  NULL,
96  NULL);
97 
99  FREE(Buffer);
100 
101  if (!INF_SUCCESS(Status))
102  {
103  DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
104  return(Status);
105  }
106 
107  return STATUS_SUCCESS;
108 }
109 
110 BOOLEAN
112  PCWSTR Section,
114 {
115  return INF_SUCCESS(InfpFindOrAddSection((PINFCACHE) InfHandle,
116  Section, Context));
117 }
118 
119 BOOLEAN
121 {
123 }
124 
125 BOOLEAN
127 {
129 }
130 
131 /* EOF */
INFSTATUS InfpAddLineWithKey(PINFCONTEXT Context, PCWSTR Key)
Definition: infput.c:224
#define INF_SUCCESS(x)
Definition: builddep.h:82
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
const uint16_t * PCWSTR
Definition: typedefs.h:55
INFSTATUS InfpFindOrAddSection(PINFCACHE Cache, PCWSTR Section, PINFCONTEXT *Context)
Definition: infput.c:190
#define MALLOC(Size)
Definition: builddep.h:73
LONG NTSTATUS
Definition: precomp.h:26
INFSTATUS InfpAddField(PINFCONTEXT Context, PCWSTR Data)
Definition: infput.c:254
uint16_t * PWCHAR
Definition: typedefs.h:54
int INFSTATUS
Definition: infpriv.h:77
HANDLE FileHandle
Definition: stats.c:38
INFSTATUS InfpBuildFileBuffer(PINFCACHE InfHandle, PWCHAR *Buffer, PULONG BufferSize)
Definition: infput.c:90
#define GENERIC_WRITE
Definition: nt_native.h:90
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
#define BufferSize
Definition: classpnp.h:419
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
#define FREE(ptr, size)
Definition: auth_des.c:64
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
BOOLEAN InfHostAddLine(PINFCONTEXT Context, PCWSTR Key)
Definition: infrosput.c:120
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS InfWriteFile(HINF InfHandle, PUNICODE_STRING FileName, PUNICODE_STRING HeaderComment)
Definition: infrosput.c:16
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
BOOLEAN InfHostAddField(PINFCONTEXT Context, PCWSTR Data)
Definition: infrosput.c:126
return STATUS_SUCCESS
Definition: btrfs.c:2938
BOOLEAN InfFindOrAddSection(HINF InfHandle, PCWSTR Section, PINFCONTEXT *Context)
Definition: infrosput.c:111