+ int c = 0;
+ while ((c = fgetc (f)) != EOF && c != '\n')
+ out += c;
+
+ return out;
+}
+
+void
+read_relocation_file (string filename)
+{
+ if (be_verbose_global)
+ progress_indication (_f ("Relocation file %s\n", filename.c_str ()));
+
+ char const *cname = filename.c_str ();
+ FILE *f = fopen (cname, "r");
+ if (!f)
+ error (_f ("can't open file %s", cname));
+
+ while (!feof (f))
+ {
+ string line = read_line (f);
+ size_t idx = line.find (' ');
+ if (idx == NPOS)
+ continue;
+
+ string command = line.substr (0, idx);
+ line = line.substr (idx + 1);
+
+ if (idx == NPOS)
+ continue;
+ idx = line.find ('=');
+
+ string variable = line.substr (0, idx);
+ string value = line.substr (idx + 1);
+
+ value = expand_environment_variables (value);
+
+ if (command == "set")
+ sane_putenv (variable.c_str(), value, true);
+ else if (command == "setdir")
+ set_env_dir (variable.c_str(), value);
+ else if (command == "setfile")
+ set_env_file (variable.c_str(), value);
+ else if (command == "prependdir")
+ prepend_env_path (variable.c_str (), value);
+ else
+ error ( _f("Unknown relocation command %s", command));
+ }
+
+ fclose (f);
+}
+
+void
+read_relocation_dir (string dirname)
+{
+ if (DIR *dir = opendir (dirname.c_str ()))
+ while (struct dirent *ent = readdir (dir))
+ {
+ File_name name (ent->d_name);
+ if (name.ext_ == "reloc")
+ read_relocation_file (dirname + "/" + name.to_string ());
+ }