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 popen _popen
|
||||
#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;
|
||||
}
|
||||
|
||||
// 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 /./,
|
||||
* /../ 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])
|
||||
{
|
||||
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);
|
||||
slashconvert(tempPath);
|
||||
convertToForwardslash(tempPath);
|
||||
|
||||
strncpy(resolved, tempPath, strlen(tempPath) + 1);
|
||||
return resolved;
|
||||
|
@ -675,9 +694,9 @@ realpath(const char *path, char resolved[MAX_PATH])
|
|||
else
|
||||
strlcpy(resolved, path + 1, sizeof(tempPath));
|
||||
|
||||
backslashconvert(resolved);
|
||||
convertToBackslash(resolved);
|
||||
PathCanonicalizeA(tempPath, resolved);
|
||||
slashconvert(tempPath);
|
||||
convertToForwardslash(tempPath);
|
||||
|
||||
// Store terminating slash in 'X:/' on Windows.
|
||||
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
|
||||
char *
|
||||
realpath_win(const char *path, char resolved[MAX_PATH])
|
||||
{
|
||||
realpath_win(const char *path, char resolved[MAX_PATH]) {
|
||||
char tempPath[MAX_PATH];
|
||||
realpath(path, tempPath);
|
||||
|
||||
|
@ -737,8 +755,7 @@ typedef struct _REPARSE_DATA_BUFFER {
|
|||
} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
|
||||
|
||||
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;
|
||||
BYTE reparseBuffer[MAX_REPARSE_SIZE];
|
||||
PBYTE reparseData;
|
||||
|
|
|
@ -231,32 +231,6 @@ char *user_from_uid(uid_t uid, int nouser) {
|
|||
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
|
||||
getuid(void) {
|
||||
return 0;
|
||||
|
|
14
sftp.c
14
sftp.c
|
@ -419,11 +419,7 @@ make_absolute(char *p, const char *pwd)
|
|||
}
|
||||
|
||||
/* convert '\\' tp '/' */
|
||||
s1 = p;
|
||||
while ((s2 = strchr(s1, '\\')) != NULL) {
|
||||
*s2 = '/';
|
||||
s1 = s2 + 1;
|
||||
}
|
||||
convertToForwardslash(p);
|
||||
|
||||
/* Append "/" if needed to the absolute windows path */
|
||||
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.
|
||||
* else they get treated as escape sequence in makeargv
|
||||
*/
|
||||
{
|
||||
char *s1 = cmd, *s2;
|
||||
while ((s2 = strchr(s1, '\\')) != NULL) {
|
||||
*s2 = '/';
|
||||
s1 = s2 + 1;
|
||||
}
|
||||
}
|
||||
convertToForwardslash(cmd);
|
||||
#endif
|
||||
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
||||
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
||||
|
|
Loading…
Reference in New Issue