realpath fix

This commit is contained in:
bagajjal 2016-12-21 19:51:27 -08:00
parent 07a658c2b7
commit 79e00ae7de
2 changed files with 9 additions and 23 deletions

View File

@ -672,38 +672,23 @@ convertToForwardslash(char *str) {
}
/*
* This method will expands all symbolic links and resolves references to /./,
* /../ and extra '/' characters in the null-terminated string named by
* This method will resolves references to /./, /../ and extra '/' characters in the null-terminated string named by
* path to produce a canonicalized absolute pathname.
*/
char *
realpath(const char *path, char resolved[MAX_PATH]) {
char tempPath[MAX_PATH];
if ((0 == strcmp(path, "./")) || (0 == strcmp(path, "."))) {
tempPath[0] = '/';
_getcwd(&tempPath[1], sizeof(tempPath) - 1);
convertToForwardslash(tempPath);
strncpy(resolved, tempPath, strlen(tempPath) + 1);
return resolved;
}
if (path[0] != '/')
strlcpy(resolved, path, sizeof(tempPath));
if (*path == '/' && *(path + 2) == ':')
strncpy(resolved, path + 1, strlen(path)); // skip the first '/'
else
strlcpy(resolved, path + 1, sizeof(tempPath));
strncpy(resolved, path, strlen(path) + 1);
convertToBackslash(resolved);
PathCanonicalizeA(tempPath, resolved);
if (_fullpath(tempPath, resolved, MAX_PATH) == NULL)
return NULL;
convertToForwardslash(tempPath);
// Store terminating slash in 'X:/' on Windows.
if (tempPath[1] == ':' && tempPath[2] == 0) {
tempPath[2] = '/';
tempPath[3] = 0;
}
resolved[0] = '/'; // will be our first slash in /x:/users/test1 format
strncpy(resolved + 1, tempPath, sizeof(tempPath) - 1);
return resolved;

1
sftp.c
View File

@ -2333,6 +2333,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
fcntl(pout[1], F_SETFD, FD_CLOEXEC);
fcntl(pin[0], F_SETFD, FD_CLOEXEC);
memcpy(full_cmd, "sftp-server.exe", 16);
sshpid = spawn_child(full_cmd, c_in, c_out, STDERR_FILENO, 0);
free(full_cmd);
}