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