Commit d580b834 authored by Peter Ganten's avatar Peter Ganten Committed by Alexandre Julliard

Fixed GetShortPathNameA.

parent 088a76b8
...@@ -889,8 +889,8 @@ BOOL DOSFS_GetFullName( LPCSTR name, BOOL check_last, DOS_FULL_NAME *full ) ...@@ -889,8 +889,8 @@ BOOL DOSFS_GetFullName( LPCSTR name, BOOL check_last, DOS_FULL_NAME *full )
* b) file does exist -> set the short filename. * b) file does exist -> set the short filename.
* - trailing slashes are reproduced in the short name, even if the * - trailing slashes are reproduced in the short name, even if the
* file is not a directory * file is not a directory
* - the absolute/relative path of the short name is reproduced in the * - the absolute/relative path of the short name is reproduced like found
* same way, like the long name * in the long name
* - longpath and shortpath may have the same adress * - longpath and shortpath may have the same adress
* Peter Ganten, 1999 * Peter Ganten, 1999
*/ */
...@@ -899,8 +899,11 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, ...@@ -899,8 +899,11 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath,
{ {
DOS_FULL_NAME full_name; DOS_FULL_NAME full_name;
LPSTR tmpshortpath; LPSTR tmpshortpath;
DWORD length = 0, pos = 0; DWORD sp = 0, lp = 0;
INT start=-1, end=-1, tmplen; int tmplen, drive;
UINT flags;
TRACE("%s\n", longpath);
if (!longpath) { if (!longpath) {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
...@@ -911,69 +914,60 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, ...@@ -911,69 +914,60 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath,
return 0; return 0;
} }
tmpshortpath = HeapAlloc( GetProcessHeap(), 0, MAX_PATHNAME_LEN ); if ( ( tmpshortpath = HeapAlloc ( GetProcessHeap(), 0, MAX_PATHNAME_LEN ) ) == NULL ) {
if ( !tmpshortpath ) {
SetLastError ( ERROR_NOT_ENOUGH_MEMORY ); SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
return 0; return 0;
} }
/* Check for Drive-Letter */ /* check for drive letter */
if ( longpath[1] == ':' ) { if ( longpath[1] == ':' ) {
lstrcpynA ( tmpshortpath, longpath, 3 ); tmpshortpath[0] = longpath[0];
length = 2; tmpshortpath[1] = ':';
pos = 2; sp = 2;
} }
/* loop over each part of the name */ if ( ( drive = DOSFS_GetPathDrive ( &longpath )) == -1 ) return 0;
while ( longpath[pos] ) { flags = DRIVE_GetFlags ( drive );
if (( longpath[pos] == '\\' ) ||
( longpath[pos+1] == '\0' ) ||
( longpath[pos] == '/')) {
if ( start != -1 ) {
if ( DOSFS_ValidDOSName ( longpath + start, TRUE )) {
tmplen = end - start + ( (( longpath[pos] == '\\' ) || ( longpath[pos] == '/' )) ? 1 : 2 );
lstrcpynA ( tmpshortpath+length, longpath+start, tmplen );
length += tmplen - 1;
}
else {
DOSFS_Hash ( longpath + start, tmpshortpath+length, FALSE, FALSE );
length = lstrlenA ( tmpshortpath );
/* Check if the path, up to this point exists */
if ( !DOSFS_GetFullName ( tmpshortpath, TRUE, &full_name ) ) {
SetLastError ( ERROR_FILE_NOT_FOUND );
return 0;
}
} while ( longpath[lp] ) {
}
if (( longpath[pos] == '\\' ) || ( longpath[pos] == '/' )) { /* check for path delimiters and reproduce them */
tmpshortpath[length] = '\\'; if ( longpath[lp] == '\\' || longpath[lp] == '/' ) {
tmpshortpath[length+1]='\0'; tmpshortpath[sp] = longpath[lp];
length++; sp++;
} lp++;
pos++;
start = -1;
end = -1;
continue; continue;
} }
if ( start == -1 ) { tmplen = strcspn ( longpath + lp, "\\/" );
start = pos; lstrcpynA ( tmpshortpath+sp, longpath + lp, tmplen+1 );
/* Check, if the current element is a valid dos name */
if ( DOSFS_ValidDOSName ( longpath + lp, !(flags & DRIVE_CASE_SENSITIVE) ) ) {
sp += tmplen;
lp += tmplen;
continue;
} }
pos++;
end = pos; /* Check if the file exists and use the existing file name */
if ( DOSFS_GetFullName ( tmpshortpath, TRUE, &full_name ) ) {
lstrcpyA ( tmpshortpath+sp, strrchr ( full_name.short_name, '\\' ) + 1 );
sp += lstrlenA ( tmpshortpath+sp );
lp += tmplen;
continue;
}
TRACE("not found!\n" );
SetLastError ( ERROR_FILE_NOT_FOUND );
return 0;
} }
lstrcpynA ( shortpath, tmpshortpath, shortlen ); lstrcpynA ( shortpath, tmpshortpath, shortlen );
length = lstrlenA ( tmpshortpath ); TRACE("returning %s\n", shortpath );
tmplen = lstrlenA ( tmpshortpath );
HeapFree ( GetProcessHeap(), 0, tmpshortpath ); HeapFree ( GetProcessHeap(), 0, tmpshortpath );
return length; return tmplen;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment