Relocate path names when searching for files.
[pspp-builds.git] / src / libpspp / str.c
index 9a7c6da8bfa8c36e50cca3cfd7b7bfe99a6cf0db..552968b5c837d02411e4e101a7ba419b1b0d7a32 100644 (file)
@@ -26,6 +26,7 @@
 #include <libpspp/message.h>
 #include <libpspp/pool.h>
 
+#include <relocatable.h>
 #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);
+    }
+}