- Create another branch for networking fixes
[reactos.git] / lib / inflib / infhostput.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 "infhost.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15 int
16 InfHostWriteFile(HINF InfHandle, const CHAR *FileName,
17 const CHAR *HeaderComment)
18 {
19 CHAR *Buffer;
20 ULONG BufferSize;
21 INFSTATUS Status;
22 FILE *File;
23
24 Status = InfpBuildFileBuffer((PINFCACHE) InfHandle, &Buffer, &BufferSize);
25 if (! INF_SUCCESS(Status))
26 {
27 errno = Status;
28 return -1;
29 }
30
31 File = fopen(FileName, "wb");
32 if (NULL == File)
33 {
34 FREE(Buffer);
35 DPRINT1("fopen() failed (errno %d)\n", errno);
36 return -1;
37 }
38
39 DPRINT("fopen() successful\n");
40
41 if (NULL != HeaderComment && '\0' != *HeaderComment)
42 {
43 fprintf(File, "; %s\r\n\r\n", HeaderComment);
44 }
45
46 if (BufferSize != fwrite(Buffer, (size_t)1, (size_t)BufferSize, File))
47 {
48 DPRINT1("fwrite() failed (errno %d)\n", errno);
49 fclose(File);
50 FREE(Buffer);
51 return -1;
52 }
53
54 fclose(File);
55
56 FREE(Buffer);
57
58 return 0;
59 }
60
61 int
62 InfHostFindOrAddSection(HINF InfHandle,
63 const CHAR *Section,
64 PINFCONTEXT *Context)
65 {
66 INFSTATUS Status;
67
68 Status = InfpFindOrAddSection((PINFCACHE) InfHandle, Section, Context);
69 if (INF_SUCCESS(Status))
70 {
71 return 0;
72 }
73 else
74 {
75 errno = Status;
76 return -1;
77 }
78 }
79
80 int
81 InfHostAddLine(PINFCONTEXT Context, const CHAR *Key)
82 {
83 INFSTATUS Status;
84
85 Status = InfpAddLineWithKey(Context, Key);
86 if (INF_SUCCESS(Status))
87 {
88 return 0;
89 }
90 else
91 {
92 errno = Status;
93 return -1;
94 }
95 }
96
97 int
98 InfHostAddField(PINFCONTEXT Context, const CHAR *Data)
99 {
100 INFSTATUS Status;
101
102 Status = InfpAddField(Context, Data);
103 if (INF_SUCCESS(Status))
104 {
105 return 0;
106 }
107 else
108 {
109 errno = Status;
110 return -1;
111 }
112 }
113
114 /* EOF */