From dcf0beac22a8f3e9cb028612d031353878ecc52c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 20 Jun 2002 23:13:06 +0000 Subject: [PATCH] Make sure that DRIVE_FindDriveRoot always returns an absolute path. --- files/dos_fs.c | 21 ++++----------------- files/drive.c | 9 ++++++--- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/files/dos_fs.c b/files/dos_fs.c index c045a981f4..74be98e54d 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -867,7 +867,6 @@ static int DOSFS_GetPathDrive( const char **name ) */ BOOL DOSFS_GetFullName( LPCSTR name, BOOL check_last, DOS_FULL_NAME *full ) { - BOOL unixabsolute = *name == '/'; BOOL found; UINT flags; char *p_l, *p_s, *root; @@ -895,7 +894,7 @@ BOOL DOSFS_GetFullName( LPCSTR name, BOOL check_last, DOS_FULL_NAME *full ) { while ((*name == '\\') || (*name == '/')) name++; } - else if (!unixabsolute) /* Relative path */ + else /* Relative path */ { lstrcpynA( root + 1, DRIVE_GetUnixCwd( full->drive ), sizeof(full->long_name) - (root - full->long_name) - 1 ); @@ -1028,7 +1027,6 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, DWORD sp = 0, lp = 0; int tmplen, drive; UINT flags; - BOOL unixabsolute = *longpath == '/'; TRACE("%s\n", debugstr_a(longpath)); @@ -1046,22 +1044,12 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, return 0; } - /* check for drive letter */ - if ( longpath[1] == ':' ) { - tmpshortpath[0] = longpath[0]; - tmpshortpath[1] = ':'; - sp = 2; - } - if ( ( drive = DOSFS_GetPathDrive ( &longpath )) == -1 ) return 0; flags = DRIVE_GetFlags ( drive ); - if ( unixabsolute ) { - tmpshortpath[0] = drive + 'A'; - tmpshortpath[1] = ':'; - tmpshortpath[2] = '\\'; - sp = 3; - } + tmpshortpath[0] = drive + 'A'; + tmpshortpath[1] = ':'; + sp = 2; while ( longpath[lp] ) { @@ -2431,4 +2419,3 @@ BOOL16 WINAPI FindClose16( HANDLE16 handle ) GlobalFree16( handle ); return TRUE; } - diff --git a/files/drive.c b/files/drive.c index 9e5b453d06..01b36adcd1 100644 --- a/files/drive.c +++ b/files/drive.c @@ -388,6 +388,9 @@ int DRIVE_FindDriveRoot( const char **path ) *p = '/'; len = strlen(buffer); + /* strip off trailing slashes */ + while (len > 0 && buffer[len - 1] == '/') buffer[--len] = 0; + while (len > 0) { /* Find the drive */ @@ -405,6 +408,7 @@ int DRIVE_FindDriveRoot( const char **path ) TRACE( "%s -> drive %c:, root='%s', name='%s'\n", *path, 'A' + drive, buffer, *path + len); *path += len; + if (!**path) *path = "\\"; return drive; } } @@ -413,9 +417,6 @@ int DRIVE_FindDriveRoot( const char **path ) level = 0; while (len > 0 && level < 1) { - /* strip off a trailing slash */ - while (len > 0 && buffer[len - 1] == '/') - buffer[--len] = 0; /* find start of the last path component */ while (len > 0 && buffer[len - 1] != '/') --len; @@ -423,6 +424,8 @@ int DRIVE_FindDriveRoot( const char **path ) if (strcmp( buffer + len, "." ) != 0) level += strcmp( buffer + len, ".." ) ? 1 : -1; buffer[len] = 0; + /* strip off trailing slashes */ + while (len > 0 && buffer[len - 1] == '/') buffer[--len] = 0; } }