88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/port/path.c,v 1.22 2004/07/11 02:59:42 momjian Exp $
11+ * $PostgreSQL: pgsql/src/port/path.c,v 1.23 2004/07/11 21:34:04 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
3333#endif
3434
3535const static char * relative_path (const char * bin_path , const char * other_path );
36+ static void make_relative (const char * my_exec_path , const char * p , char * ret_path );
3637static void trim_directory (char * path );
3738static void trim_trailing_separator (char * path );
3839
@@ -43,15 +44,6 @@ static void trim_trailing_separator(char *path);
4344 (p)++; \
4445}
4546
46- /* Macro creates a relative path */
47- #define MAKE_RELATIVE \
48- do { \
49- StrNCpy(path, my_exec_path, MAXPGPATH); \
50- trim_directory(path); \
51- trim_directory(path); \
52- snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
53- } while (0)
54-
5547/*
5648 * first_dir_separator
5749 */
@@ -140,13 +132,13 @@ get_progname(const char *argv0)
140132void
141133get_share_path (const char * my_exec_path , char * ret_path )
142134{
143- char path [MAXPGPATH ];
144135 const char * p ;
145136
146137 if ((p = relative_path (PGBINDIR , PGSHAREDIR )))
147- MAKE_RELATIVE ;
138+ make_relative ( my_exec_path , p , ret_path ) ;
148139 else
149140 StrNCpy (ret_path , PGSHAREDIR , MAXPGPATH );
141+ canonicalize_path (ret_path );
150142}
151143
152144
@@ -157,13 +149,13 @@ get_share_path(const char *my_exec_path, char *ret_path)
157149void
158150get_etc_path (const char * my_exec_path , char * ret_path )
159151{
160- char path [MAXPGPATH ];
161152 const char * p ;
162153
163154 if ((p = relative_path (PGBINDIR , SYSCONFDIR )))
164- MAKE_RELATIVE ;
155+ make_relative ( my_exec_path , p , ret_path ) ;
165156 else
166157 StrNCpy (ret_path , SYSCONFDIR , MAXPGPATH );
158+ canonicalize_path (ret_path );
167159}
168160
169161
@@ -174,13 +166,13 @@ get_etc_path(const char *my_exec_path, char *ret_path)
174166void
175167get_include_path (const char * my_exec_path , char * ret_path )
176168{
177- char path [MAXPGPATH ];
178169 const char * p ;
179170
180171 if ((p = relative_path (PGBINDIR , INCLUDEDIR )))
181- MAKE_RELATIVE ;
172+ make_relative ( my_exec_path , p , ret_path ) ;
182173 else
183174 StrNCpy (ret_path , INCLUDEDIR , MAXPGPATH );
175+ canonicalize_path (ret_path );
184176}
185177
186178
@@ -191,13 +183,13 @@ get_include_path(const char *my_exec_path, char *ret_path)
191183void
192184get_pkginclude_path (const char * my_exec_path , char * ret_path )
193185{
194- char path [MAXPGPATH ];
195186 const char * p ;
196187
197188 if ((p = relative_path (PGBINDIR , PKGINCLUDEDIR )))
198- MAKE_RELATIVE ;
189+ make_relative ( my_exec_path , p , ret_path ) ;
199190 else
200191 StrNCpy (ret_path , PKGINCLUDEDIR , MAXPGPATH );
192+ canonicalize_path (ret_path );
201193}
202194
203195
@@ -210,13 +202,13 @@ get_pkginclude_path(const char *my_exec_path, char *ret_path)
210202void
211203get_pkglib_path (const char * my_exec_path , char * ret_path )
212204{
213- char path [MAXPGPATH ];
214205 const char * p ;
215206
216207 if ((p = relative_path (PGBINDIR , PKGLIBDIR )))
217- MAKE_RELATIVE ;
208+ make_relative ( my_exec_path , p , ret_path ) ;
218209 else
219210 StrNCpy (ret_path , PKGLIBDIR , MAXPGPATH );
211+ canonicalize_path (ret_path );
220212}
221213
222214
@@ -229,13 +221,13 @@ get_pkglib_path(const char *my_exec_path, char *ret_path)
229221void
230222get_locale_path (const char * my_exec_path , char * ret_path )
231223{
232- char path [MAXPGPATH ];
233224 const char * p ;
234225
235226 if ((p = relative_path (PGBINDIR , LOCALEDIR )))
236- MAKE_RELATIVE ;
227+ make_relative ( my_exec_path , p , ret_path ) ;
237228 else
238229 StrNCpy (ret_path , LOCALEDIR , MAXPGPATH );
230+ canonicalize_path (ret_path );
239231}
240232
241233
@@ -270,6 +262,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
270262 {
271263 /* set for libpq to use */
272264 snprintf (env_path , sizeof (env_path ), "PGLOCALEDIR=%s" , path );
265+ canonicalize_path (env_path );
273266 putenv (strdup (env_path ));
274267 }
275268#endif
@@ -280,11 +273,26 @@ set_pglocale_pgservice(const char *argv0, const char *app)
280273
281274 /* set for libpq to use */
282275 snprintf (env_path , sizeof (env_path ), "PGSYSCONFDIR=%s" , path );
276+ canonicalize_path (env_path );
283277 putenv (strdup (env_path ));
284278 }
285279}
286280
287281
282+ /*
283+ * make_relative - adjust path to be relative to bin/
284+ */
285+ static void
286+ make_relative (const char * my_exec_path , const char * p , char * ret_path )
287+ {
288+ char path [MAXPGPATH ];
289+
290+ StrNCpy (path , my_exec_path , MAXPGPATH );
291+ trim_directory (path );
292+ trim_directory (path );
293+ snprintf (ret_path , MAXPGPATH , "%s/%s" , path , p );
294+ }
295+
288296
289297/*
290298 * relative_path
@@ -391,7 +399,10 @@ trim_trailing_separator(char *path)
391399 char * p = path + strlen (path );
392400
393401#ifdef WIN32
394- /* Skip over network and drive specifiers for win32 */
402+ /*
403+ * Skip over network and drive specifiers for win32.
404+ * Set 'path' to point to the last character to keep.
405+ */
395406 if (strlen (path ) >= 2 )
396407 {
397408 if (IS_DIR_SEP (path [0 ]) && IS_DIR_SEP (path [1 ]))
0 commit comments