16 int bftpd_cwd_chdir(char *dir)
18 char *tmp = bftpd_cwd_mappath(dir);
23 cwd = realloc(cwd, strlen(tmp) + 1);
30 char *bftpd_cwd_getcwd()
35 void appendpath(char *result, char *tmp)
37 if (!strcmp(tmp, "."))
39 if (!strcmp(tmp, "..")) {
40 if (strcmp(result, "/")) {
41 if (result[strlen(result) - 1] == '/')
42 result[strlen(result) - 1] = '\0';
44 while (strchr(tmp, '/'))
45 tmp = strchr(tmp, '/') + 1;
47 if ((result[strlen(result) - 1] == '/') && (strlen(result) > 1))
48 result[strlen(result) - 1] = '\0';
51 if (result[strlen(result) - 1] != '/')
57 char *bftpd_cwd_mappath(char *path)
59 char *result = malloc(strlen(path) + strlen(cwd) + 10);
60 char *path2 = strdup(path);
66 while (strchr(path2, '/')) {
68 *strchr(tmp, '/') = '\0';
69 cutto(path2, strlen(tmp) + 1);
70 appendpath(result, tmp);
73 appendpath(result, path2);