Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / sdk / lib / inflib / infrosput.c
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
15 NTSTATUS
16 InfWriteFile(HINF InfHandle,
17 PUNICODE_STRING FileName,
18 PUNICODE_STRING HeaderComment)
19 {
20 OBJECT_ATTRIBUTES ObjectAttributes;
21 IO_STATUS_BLOCK IoStatusBlock;
22 HANDLE FileHandle;
23 NTSTATUS Status;
24 INFSTATUS InfStatus;
25 PWCHAR Buffer;
26 ULONG BufferSize;
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 */
39 InitializeObjectAttributes(&ObjectAttributes,
40 FileName,
41 0,
42 NULL,
43 NULL);
44
45 Status = NtOpenFile(&FileHandle,
46 GENERIC_WRITE | SYNCHRONIZE,
47 &ObjectAttributes,
48 &IoStatusBlock,
49 0,
50 FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
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");
74 NtWriteFile(FileHandle,
75 NULL,
76 NULL,
77 NULL,
78 &IoStatusBlock,
79 HeaderBuffer,
80 HeaderBufferSize,
81 NULL,
82 NULL);
83 FREE(HeaderBuffer);
84 }
85 }
86
87 /* Write main contents */
88 Status = NtWriteFile(FileHandle,
89 NULL,
90 NULL,
91 NULL,
92 &IoStatusBlock,
93 Buffer,
94 BufferSize,
95 NULL,
96 NULL);
97
98 NtClose(FileHandle);
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
111 InfFindOrAddSection(HINF InfHandle,
112 PCWSTR Section,
113 PINFCONTEXT *Context)
114 {
115 return INF_SUCCESS(InfpFindOrAddSection((PINFCACHE) InfHandle,
116 Section, Context));
117 }
118
119 BOOLEAN
120 InfHostAddLine(PINFCONTEXT Context, PCWSTR Key)
121 {
122 return INF_SUCCESS(InfpAddLineWithKey(Context, Key));
123 }
124
125 BOOLEAN
126 InfHostAddField(PINFCONTEXT Context, PCWSTR Data)
127 {
128 return INF_SUCCESS(InfpAddField(Context, Data));
129 }
130
131 /* EOF */