1/**************************************************
2 * SQLGetInstalledDrivers
3 *
4 **************************************************
5 * This code was created by Peter Harvey @ CodeByDesign.
6 * Released under LGPL 28.JAN.99
7 *
8 * Contributions from...
9 * -----------------------------------------------
10 * Peter Harvey - pharvey@codebydesign.com
11 **************************************************/
12#include <config.h>
13#include <odbcinstext.h>
14
15BOOL SQLGetInstalledDrivers( LPSTR pszBuf,
16 WORD nBufMax,
17 WORD *pnBufOut )
18{
19 HINI hIni;
20 WORD nBufPos = 0;
21 WORD nToCopySize = 0;
22 char szObjectName[INI_MAX_OBJECT_NAME+1];
23 char szIniName[ ODBC_FILENAME_MAX * 2 + 1 ];
24 char b1[ ODBC_FILENAME_MAX + 1 ], b2[ ODBC_FILENAME_MAX + 1 ];
25
26 inst_logClear();
27
28#ifdef VMS
29 sprintf( szIniName, "%s:%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
30#else
31 sprintf( szIniName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
32#endif
33
34#ifdef __OS2__
35 if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', TRUE, 1L ) != INI_SUCCESS )
36#else
37 if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', TRUE ) != INI_SUCCESS )
38#endif
39 {
40 inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" );
41 return FALSE;
42 }
43
44 memset( pszBuf, '\0', nBufMax );
45
46 iniObjectFirst( hIni );
47 while ( iniObjectEOL( hIni ) == FALSE )
48 {
49 iniObject( hIni, szObjectName );
50 if ( strcmp( szObjectName, "ODBC" ) == 0 )
51 {
52 iniObjectNext( hIni );
53 continue;
54 }
55
56 if ( (strlen( szObjectName )+1) > (nBufMax - nBufPos) )
57 {
58 nToCopySize = nBufMax - nBufPos;
59 strncpy( &(pszBuf[nBufPos]), szObjectName, nToCopySize );
60 nBufPos = nBufMax;
61 break;
62 }
63 else
64 {
65 strcpy( &(pszBuf[nBufPos]), szObjectName );
66 nBufPos += strlen( szObjectName )+1;
67 }
68 iniObjectNext( hIni );
69 }
70 iniClose( hIni );
71
72 if ( pnBufOut )
73 *pnBufOut = nBufPos;
74
75 return TRUE;
76}
77
78
79BOOL INSTAPI SQLGetInstalledDriversW (LPWSTR lpszBuf,
80 WORD cbBufMax,
81 WORD * pcbBufOut)
82{
83 char *path;
84 BOOL ret;
85
86 inst_logClear();
87
88 path = calloc( cbBufMax, 1 );
89
90 ret = SQLGetInstalledDrivers( path, cbBufMax, pcbBufOut );
91
92 if ( ret )
93 {
94 _multi_string_copy_to_wide( lpszBuf, path, cbBufMax );
95 }
96
97 free( path );
98
99 return ret;
100}
101