Removed dependency on 16-bit file I/O functions.
[wine/multimedia.git] / dlls / setupapi / infparse.c
blobe095834806873a42367915b5706cf2c5927fe17b
1 /*
2 * SetupX .inf file parsing functions
4 * FIXME: return values ???
5 */
7 #include "debugtools.h"
8 #include "windef.h"
9 #include "winbase.h"
10 #include "heap.h"
11 #include "wine/winbase16.h"
12 #include "setupx16.h"
14 DEFAULT_DEBUG_CHANNEL(setupx);
16 WORD InfNumEntries = 0;
17 INF_FILE *InfList = NULL;
18 HINF16 IP_curr_handle = 0;
20 RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
22 HFILE hFile = _lopen(lpInfFileName, OF_READ);
24 if (!lphInf)
25 return IP_ERROR;
27 /* this could be improved by checking for already freed handles */
28 if (IP_curr_handle == 0xffff)
29 return ERR_IP_OUT_OF_HANDLES;
31 if (hFile != HFILE_ERROR)
33 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
34 InfList[InfNumEntries].hInf = IP_curr_handle++;
35 InfList[InfNumEntries].hInfFile = hFile;
36 InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0,
37 strlen(lpInfFileName)+1);
38 strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName );
39 *lphInf = InfList[InfNumEntries].hInf;
40 InfNumEntries++;
41 TRACE("ret handle %d.\n", *lphInf);
42 return OK;
44 *lphInf = 0xffff;
45 return ERR_IP_INVALID_INFFILE;
48 BOOL IP_FindInf(HINF16 hInf, WORD *ret)
50 WORD n;
52 for (n=0; n < InfNumEntries; n++)
53 if (InfList[n].hInf == hInf)
55 *ret = n;
56 return TRUE;
58 return FALSE;
62 LPCSTR IP_GetFileName(HINF16 hInf)
64 WORD n;
65 if (IP_FindInf(hInf, &n))
67 return InfList[n].lpInfFileName;
69 return NULL;
72 RETERR16 IP_CloseInf(HINF16 hInf)
74 int i;
75 WORD n;
76 RETERR16 res = ERR_IP_INVALID_HINF;
78 if (IP_FindInf(hInf, &n))
80 _lclose(InfList[n].hInfFile);
81 HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName);
82 for (i=n; i < InfNumEntries-1; i++)
83 InfList[i] = InfList[i+1];
84 InfNumEntries--;
85 InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
86 res = OK;
88 return res;
91 /***********************************************************************
92 * IpOpen16
95 RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
97 TRACE("('%s', %p)\n", lpInfFileName, lphInf);
98 return IP_OpenInf(lpInfFileName, lphInf);
101 /***********************************************************************
102 * IpClose16
104 RETERR16 WINAPI IpClose16(HINF16 hInf)
106 return IP_CloseInf(hInf);
109 /***********************************************************************
110 * IpGetProfileString16
112 RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen)
114 TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry);
115 GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
116 return 0;