static void do_test(int argc, const char **argv) { int j; char bfr[MAXPATHLEN]; for (j = 1; j < argc; j++) { if (argv[j] == 0) break; (void) trimpath(strcpy(bfr, argv[j]), "/usr/local"); PRINTF("%d: %s => %s\n", j, argv[j], bfr); } }
/* make pathname from an optional suffix and a file name relative to * a path or the home directory */ u_char /* 0=too long */ dcc_fnm2abs(DCC_PATH path, /* put it here */ const char *nm, const char *suffix) { DCC_PATH tmp; int i; #ifdef DCC_WIN32 char *p; DWORD lasterror; #endif /* the answer is the input pathname if it is null */ if (!nm || *nm == '\0') { path[0] = '\0'; return 0; } if (!suffix) suffix = ""; #ifdef DCC_WIN32 i = snprintf(tmp, sizeof(DCC_PATH), "%s%s", nm, suffix); if (i >= ISZ(DCC_PATH)) { path[0] = '\0'; return 0; } lasterror = GetLastError(); GetFullPathName(tmp, sizeof(DCC_PATH), path, &p); SetLastError(lasterror); return 1; #else if (nm[0] == '/' || dcc_homedir[0] == '\0') { i = snprintf(tmp, sizeof(tmp), "%s%s", nm, suffix); } else { i = snprintf(tmp, sizeof(tmp), "%s/%s%s", dcc_homedir, nm, suffix); } trimpath(path, tmp); if (i >= ISZ(tmp)) { /* too long */ i = strlen(path); if (i > ISZ(DCC_PATH)-4) i = ISZ(DCC_PATH)-4; strcpy(&path[i], "..."); return 0; } return 1; #endif }
/* Make a home directory relative pathname from a file name * and an optional suffix. * An absolute path unrelated to the home directory remains absolute. * The target path can be the input name. */ u_char /* 0=too long */ dcc_fnm2rel(DCC_PATH new_path, const char *nm, const char *suffix) { #ifdef DCC_WIN32 return dcc_fnm2abs(new_path, nm, suffix); #else DCC_PATH tmp; int i; const char *p, *p1; /* the answer is the input pathname if it is null */ if (!nm || *nm == '\0') { if (new_path != nm) new_path[0] = '\0'; return 0; } if (suffix || new_path == nm) { p = tmp; i = snprintf(tmp, sizeof(tmp), "%s%s", nm, suffix ? suffix : ""); } else { p = nm; i = strlen(p); } if (i >= ISZ(tmp)) { /* too long */ if (new_path != nm) new_path[0] = '\0'; return 0; } if (p[dcc_homedir_len] == '/' && !strncmp(p, dcc_homedir, dcc_homedir_len)) { p1 = p + dcc_homedir_len; do { ++p1; } while (*p1 == '/'); if (*p1 != '\0') p = p1; } trimpath(new_path, p); return 1; #endif }