From 46b52782d51c442adc7fefe498c5392138f6c9fe Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 8 Feb 2009 07:51:13 +0900 Subject: [PATCH] Relocate path names when searching for files. When searching for configuration files etc. in a search path, relocate the filenames before testing for their existence. Closes bug #25508 --- src/data/file-name.c | 1 + src/libpspp/str.c | 18 ++++++++++++++++++ src/libpspp/str.h | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/data/file-name.c b/src/data/file-name.c index 14afd60e..e9411b65 100644 --- a/src/data/file-name.c +++ b/src/data/file-name.c @@ -138,6 +138,7 @@ fn_search_path (const char *base_name, const char *path_) if (!ds_is_empty (&file) && !ISSLASH (ds_last (&file))) ds_put_char (&file, '/'); ds_put_cstr (&file, base_name); + ds_relocate (&file); /* Check whether file exists. */ if (fn_exists (ds_cstr (&file))) diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 9a7c6da8..552968b5 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -26,6 +26,7 @@ #include #include +#include #include "minmax.h" #include "xalloc.h" #include "xsize.h" @@ -1396,3 +1397,20 @@ ds_put_char_multiple (struct string *st, int ch, size_t cnt) { memset (ds_put_uninit (st, cnt), ch, cnt); } + + +/* If relocation has been enabled, replace ST, + with its relocated version */ +void +ds_relocate (struct string *st) +{ + const char *orig = ds_cstr (st); + const char *rel = relocate (orig); + + if ( orig != rel) + { + ds_clear (st); + ds_put_cstr (st, rel); + free ((char *) rel); + } +} diff --git a/src/libpspp/str.h b/src/libpspp/str.h index ff00b359..ca990dbc 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -218,4 +218,8 @@ void ds_put_format (struct string *, const char *, ...) PRINTF_FORMAT (2, 3); char *ds_put_uninit (struct string *st, size_t incr); +/* Other */ +/* calls relocate from gnulib on ST */ +void ds_relocate (struct string *st); + #endif /* str_h */ -- 2.30.2