1/**************************************************
2 *
3 **************************************************
4 * This code was created by Peter Harvey @ CodeByDesign.
5 * Released under LGPL 28.JAN.99
6 *
7 * Contributions from...
8 * -----------------------------------------------
9 * Peter Harvey - pharvey@codebydesign.com
10 **************************************************/
11#include <config.h>
12#include <odbcinstext.h>
13
14/*
15 * Add the historic ODBCINI value, mainly for applix.
16 */
17
18#ifdef VMS
19
20char *odbcinst_system_file_path( char *buffer )
21{
22 char *path;
23
24 if (( path = getvmsenv( "ODBCSYSINI" ))) {
25 strcpy( buffer, path );
26 return buffer;
27 }
28#ifdef SYSTEM_FILE_PATH
29 else {
30 return SYSTEM_FILE_PATH;
31 }
32#else
33 else {
34 return "ODBC_LIBDIR:";
35 }
36#endif
37}
38
39char *odbcinst_system_file_name( char *buffer )
40{
41 char *path;
42
43 if (( path = getvmsenv( "ODBCINSTINI" ))) {
44 strcpy( buffer, path );
45 return path;
46 }
47 else {
48 return "ODBCINST.INI";
49 }
50}
51
52char *odbcinst_user_file_path( char *buffer )
53{
54 return "ODBC_LIBDIR:";
55}
56
57char *odbcinst_user_file_name( char *buffer )
58{
59 return "ODBCINST.INI";
60}
61
62BOOL _odbcinst_SystemINI( char *pszFileName, BOOL bVerify )
63{
64 FILE *hFile;
65 char b1[ ODBC_FILENAME_MAX + 1 ];
66
67 sprintf( pszFileName, "%s:odbc.ini", odbcinst_system_file_path( b1 ));
68
69 if ( bVerify )
70 {
71 hFile = uo_fopen( pszFileName, "r" );
72 if ( hFile )
73 uo_fclose( hFile );
74 else
75 return FALSE;
76 }
77
78 return TRUE;
79}
80
81#else
82
83char *odbcinst_system_file_name( char *buffer )
84{
85 char *path;
86 static char save_path[ ODBC_FILENAME_MAX + 1 ];
87 static int saved = 0;
88
89 if ( saved ) {
90 return save_path;
91 }
92
93 if (( path = getenv( "ODBCINSTINI" ))) {
94 strncpy( buffer, path, ODBC_FILENAME_MAX );
95 strncpy( save_path, buffer, ODBC_FILENAME_MAX );
96 saved = 1;
97 return buffer;
98 }
99 else {
100 strcpy( save_path, "odbcinst.ini" );
101 saved = 1;
102 return "odbcinst.ini";
103 }
104}
105
106char *odbcinst_system_file_path( char *buffer )
107{
108 char *path;
109 static char save_path[ ODBC_FILENAME_MAX + 1 ];
110 static int saved = 0;
111
112 if ( saved ) {
113 return save_path;
114 }
115
116 if (( path = getenv( "ODBCSYSINI" ))) {
117 strncpy( buffer, path, ODBC_FILENAME_MAX );
118 strncpy( save_path, buffer, ODBC_FILENAME_MAX );
119 saved = 1;
120 return buffer;
121 }
122#ifdef SYSTEM_FILE_PATH
123 else {
124 strcpy( save_path, SYSTEM_FILE_PATH );
125 saved = 1;
126 return SYSTEM_FILE_PATH;
127 }
128#else
129 else {
130 strcpy( save_path, "/etc" );
131 saved = 1;
132 return "/etc";
133 }
134#endif
135}
136
137char *odbcinst_user_file_name( char *buffer )
138{
139 return ".odbcinst.ini";
140}
141
142char *odbcinst_user_file_path( char *buffer )
143{
144 char *path;
145 static char save_path[ ODBC_FILENAME_MAX + 1 ];
146 static int saved = 0;
147
148 if ( saved ) {
149 return save_path;
150 }
151
152 if (( path = getenv( "HOME" ))) {
153 strncpy( buffer, path, ODBC_FILENAME_MAX );
154 strncpy( save_path, buffer, ODBC_FILENAME_MAX );
155 saved = 1;
156 return buffer;
157 }
158 else {
159 return "/home";
160 }
161}
162
163BOOL _odbcinst_SystemINI( char *pszFileName, BOOL bVerify )
164{
165 FILE *hFile;
166 char b1[ ODBC_FILENAME_MAX + 1 ];
167
168 sprintf( pszFileName, "%s/odbc.ini", odbcinst_system_file_path( b1 ));
169
170 if ( bVerify )
171 {
172 /* try opening for read */
173 hFile = uo_fopen( pszFileName, "r" );
174 if ( hFile )
175 uo_fclose( hFile );
176 else
177 {
178 /* does not exist so try creating it */
179 hFile = uo_fopen( pszFileName, "w" );
180 if ( hFile )
181 uo_fclose( hFile );
182 else
183 return FALSE;
184 }
185 }
186
187 return TRUE;
188}
189
190#endif
191
192