/* If the path has the home directory in it, replace it with a tilde. */ int tilde_expand(char *buf, int buf_size, const char *path1) { char path[MAX_FILENAME_SIZE]; char *homedir; int ret = 0; if (!is_abs_path(path1)) { if (*path1 == '~') { if (path1[1] == '\0' || path1[1] == '/') { homedir = getenv("HOME"); if (homedir) { pstrcpy(path, sizeof(path), homedir); #ifdef CONFIG_WIN32 path_win_to_unix(path); #endif remove_slash(path); pstrcat(path, sizeof(path), path1 + 1); path1 = path; } } else { /* CG: should get info from getpwnam */ pstrcpy(path, sizeof(path), "/home/"); pstrcat(path, sizeof(path), path1 + 1); path1 = path; } ret = 1; } } pstrcpy(buf, buf_size, path1); return ret; }
/* canonize the path and make it absolute */ void canonize_absolute_path(char *buf, int buf_size, const char *path1) { char cwd[MAX_FILENAME_SIZE]; char path[MAX_FILENAME_SIZE]; char *homedir; if (!is_abs_path(path1)) { /* XXX: should call it again */ if (*path1 == '~' && (path1[1] == '\0' || path1[1] == '/')) { homedir = getenv("HOME"); if (homedir) { pstrcpy(path, sizeof(path), homedir); pstrcat(path, sizeof(path), path1 + 1); goto next; } } /* CG: not sufficient for windows drives */ getcwd(cwd, sizeof(cwd)); #ifdef WIN32 path_win_to_unix(cwd); #endif makepath(path, sizeof(path), cwd, path1); } else { pstrcpy(path, sizeof(path), path1); } next: canonize_path(buf, buf_size, path); }
/* canonize the path and make it absolute */ void canonize_absolute_path_old(char *buf, int buf_size, const char *path1) { char path[1024]; if (!is_abs_path(path1)) { /* XXX: should call it again */ getcwd(path, sizeof(path)); #ifdef WIN32 path_win_to_unix(path); #endif pstrcat(path, sizeof(path), "/"); pstrcat(path, sizeof(path), path1); } else { pstrcpy(path, sizeof(path), path1); } canonize_path(buf, buf_size, path); }
/* canonize the path and make it absolute */ void canonize_absolute_path(char *buf, int buf_size, const char *path1) { char cwd[MAX_FILENAME_SIZE]; char path[MAX_FILENAME_SIZE]; if (is_abs_path(path1)) { pstrcpy(path, sizeof(path), path1); } else { /* CG: not sufficient for windows drives */ if (!expand_unix_home(path1, path, sizeof(path))) { getcwd(cwd, sizeof(cwd)); path_win_to_unix(cwd); makepath(path, sizeof(path), cwd, path1); } } canonize_path(buf, buf_size, path); }
/* canonicalize the path and make it absolute */ void canonize_absolute_path(char *buf, int buf_size, const char *path1) { char cwd[MAX_FILENAME_SIZE]; char path[MAX_FILENAME_SIZE]; if (!is_abs_path(path1)) { if (*path1 == '~') { tilde_expand(path, MAX_FILENAME_SIZE, path1); path1 = path; } else { /* CG: not sufficient for windows drives */ /* CG: should test result */ getcwd(cwd, sizeof(cwd)); #ifdef CONFIG_WIN32 path_win_to_unix(cwd); #endif makepath(path, sizeof(path), cwd, path1); path1 = path; } } canonize_path(buf, buf_size, path1); }