Making forwardslash/backslash converter methods available in posix layer
This commit is contained in:
parent
50ddd23474
commit
07a658c2b7
|
@ -159,3 +159,6 @@ explicit_bzero(void *b, size_t len);
|
||||||
#define fopen w32_fopen_utf8
|
#define fopen w32_fopen_utf8
|
||||||
#define popen _popen
|
#define popen _popen
|
||||||
#define pclose _pclose
|
#define pclose _pclose
|
||||||
|
|
||||||
|
void convertToBackslash(char *str);
|
||||||
|
void convertToForwardslash(char *str);
|
||||||
|
|
|
@ -651,20 +651,39 @@ readlink(const char *path, char *link, int linklen)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert forward slash to back slash
|
||||||
|
void
|
||||||
|
convertToBackslash(char *str) {
|
||||||
|
while (*str) {
|
||||||
|
if (*str == '/')
|
||||||
|
*str = '\\';
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert back slash to forward slash
|
||||||
|
void
|
||||||
|
convertToForwardslash(char *str) {
|
||||||
|
while (*str) {
|
||||||
|
if (*str == '\\')
|
||||||
|
*str = '/';
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method will expands all symbolic links and resolves references to /./,
|
* This method will expands all symbolic links and resolves references to /./,
|
||||||
* /../ and extra '/' characters in the null-terminated string named by
|
* /../ and extra '/' characters in the null-terminated string named by
|
||||||
* path to produce a canonicalized absolute pathname.
|
* path to produce a canonicalized absolute pathname.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
realpath(const char *path, char resolved[MAX_PATH])
|
realpath(const char *path, char resolved[MAX_PATH]) {
|
||||||
{
|
|
||||||
char tempPath[MAX_PATH];
|
char tempPath[MAX_PATH];
|
||||||
|
|
||||||
if ((0 == strcmp(path, "./")) || (0 == strcmp(path, "."))) {
|
if ((0 == strcmp(path, "./")) || (0 == strcmp(path, "."))) {
|
||||||
tempPath[0] = '/';
|
tempPath[0] = '/';
|
||||||
_getcwd(&tempPath[1], sizeof(tempPath) - 1);
|
_getcwd(&tempPath[1], sizeof(tempPath) - 1);
|
||||||
slashconvert(tempPath);
|
convertToForwardslash(tempPath);
|
||||||
|
|
||||||
strncpy(resolved, tempPath, strlen(tempPath) + 1);
|
strncpy(resolved, tempPath, strlen(tempPath) + 1);
|
||||||
return resolved;
|
return resolved;
|
||||||
|
@ -675,9 +694,9 @@ realpath(const char *path, char resolved[MAX_PATH])
|
||||||
else
|
else
|
||||||
strlcpy(resolved, path + 1, sizeof(tempPath));
|
strlcpy(resolved, path + 1, sizeof(tempPath));
|
||||||
|
|
||||||
backslashconvert(resolved);
|
convertToBackslash(resolved);
|
||||||
PathCanonicalizeA(tempPath, resolved);
|
PathCanonicalizeA(tempPath, resolved);
|
||||||
slashconvert(tempPath);
|
convertToForwardslash(tempPath);
|
||||||
|
|
||||||
// Store terminating slash in 'X:/' on Windows.
|
// Store terminating slash in 'X:/' on Windows.
|
||||||
if (tempPath[1] == ':' && tempPath[2] == 0) {
|
if (tempPath[1] == ':' && tempPath[2] == 0) {
|
||||||
|
@ -692,8 +711,7 @@ realpath(const char *path, char resolved[MAX_PATH])
|
||||||
|
|
||||||
// like realpathWin32() but takes out the first slash so that windows systems can work on the actual file or directory
|
// like realpathWin32() but takes out the first slash so that windows systems can work on the actual file or directory
|
||||||
char *
|
char *
|
||||||
realpath_win(const char *path, char resolved[MAX_PATH])
|
realpath_win(const char *path, char resolved[MAX_PATH]) {
|
||||||
{
|
|
||||||
char tempPath[MAX_PATH];
|
char tempPath[MAX_PATH];
|
||||||
realpath(path, tempPath);
|
realpath(path, tempPath);
|
||||||
|
|
||||||
|
@ -737,8 +755,7 @@ typedef struct _REPARSE_DATA_BUFFER {
|
||||||
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
|
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
ResolveLink(wchar_t * tLink, wchar_t *ret, DWORD * plen, DWORD Flags)
|
ResolveLink(wchar_t * tLink, wchar_t *ret, DWORD * plen, DWORD Flags) {
|
||||||
{
|
|
||||||
HANDLE fileHandle;
|
HANDLE fileHandle;
|
||||||
BYTE reparseBuffer[MAX_REPARSE_SIZE];
|
BYTE reparseBuffer[MAX_REPARSE_SIZE];
|
||||||
PBYTE reparseData;
|
PBYTE reparseData;
|
||||||
|
|
|
@ -231,32 +231,6 @@ char *user_from_uid(uid_t uid, int nouser) {
|
||||||
return "-";
|
return "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO - this is moved from realpath.c in openbsdcompat. Review and finalize its position*/
|
|
||||||
|
|
||||||
#include <Shlwapi.h>
|
|
||||||
|
|
||||||
void backslashconvert(char *str)
|
|
||||||
{
|
|
||||||
while (*str) {
|
|
||||||
if (*str == '/')
|
|
||||||
*str = '\\'; // convert forward slash to back slash
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert back slash to forward slash
|
|
||||||
void slashconvert(char *str)
|
|
||||||
{
|
|
||||||
while (*str) {
|
|
||||||
if (*str == '\\')
|
|
||||||
*str = '/'; // convert back slash to forward slash
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uid_t
|
uid_t
|
||||||
getuid(void) {
|
getuid(void) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
14
sftp.c
14
sftp.c
|
@ -419,11 +419,7 @@ make_absolute(char *p, const char *pwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert '\\' tp '/' */
|
/* convert '\\' tp '/' */
|
||||||
s1 = p;
|
convertToForwardslash(p);
|
||||||
while ((s2 = strchr(s1, '\\')) != NULL) {
|
|
||||||
*s2 = '/';
|
|
||||||
s1 = s2 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Append "/" if needed to the absolute windows path */
|
/* Append "/" if needed to the absolute windows path */
|
||||||
if (p && p[0] != '\0' && p[1] == ':') {
|
if (p && p[0] != '\0' && p[1] == ':') {
|
||||||
|
@ -1516,13 +1512,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
|
||||||
* convert '\\' to '/' in Windows styled paths.
|
* convert '\\' to '/' in Windows styled paths.
|
||||||
* else they get treated as escape sequence in makeargv
|
* else they get treated as escape sequence in makeargv
|
||||||
*/
|
*/
|
||||||
{
|
convertToForwardslash(cmd);
|
||||||
char *s1 = cmd, *s2;
|
|
||||||
while ((s2 = strchr(s1, '\\')) != NULL) {
|
|
||||||
*s2 = '/';
|
|
||||||
s1 = s2 + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
||||||
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
||||||
|
|
Loading…
Reference in New Issue