static char *set_curr_prefix (const char *ModuleName) { if (curr_prefix) free (curr_prefix); set_current_prefix (ModuleName); return curr_prefix; }
char *relocaten (const char *ModuleName, const char *path) { char *relative_path, *relocated_path, *relocated_short_path; int relative_path_len; if (!curr_prefix) set_current_prefix (ModuleName); // printf ("path: %s\n", path); // printf ("orig_prefix: %s\n", orig_prefix); // printf ("curr_prefix: %s\n", curr_prefix); // if (strncmp (orig_prefix, path, orig_prefix_len)) // if (strcmp (orig_prefix, path)) // return (char *) path; relative_path = (char *) path + orig_prefix_len; // printf ("relative_path: %s\n", relative_path); relative_path_len = strlen (relative_path); relocated_path = malloc (curr_prefix_len + relative_path_len + 1); strcpy (relocated_path, curr_prefix); strcat (relocated_path, relative_path); // printf ("relocated_path: %s\n", relocated_path); relocated_short_path = getshortpath (relocated_path); // printf ("relocated_short_path: %s\n", relocated_short_path); if (relocated_short_path) { if (relocated_short_path != relocated_path) free (relocated_path); return relocated_short_path; } else return relocated_path; }
// Strip the installation prefix and replace it // with the current installation prefix; return the relocated path. char *relocatep(const char *path) { #if DEBUG fprintf(stderr, "relocatep: path = %s\n", path); fprintf(stderr, "relocatep: INSTALLPATH = %s\n", INSTALLPATH); fprintf(stderr, "relocatep: INSTALLPATHLEN = %d\n", INSTALLPATHLEN); #endif if (!curr_prefix) set_current_prefix(); if (strncmp(INSTALLPATH, path, INSTALLPATHLEN)) return strsave(path); char *relative_path = (char *)path + INSTALLPATHLEN; size_t relative_path_len = strlen(relative_path); char *relocated_path = new char[curr_prefix_len + relative_path_len + 1]; strcpy(relocated_path, curr_prefix); strcat(relocated_path, relative_path); #if DEBUG fprintf(stderr, "relocated_path: %s\n", relocated_path); #endif /* DEBUG */ return relocated_path; }