GetLongPathName rewrite.

This commit is contained in:
Petr Tomasek 2000-02-20 19:14:17 +00:00 committed by Alexandre Julliard
parent cf1bcc496b
commit 788a9f7680
1 changed files with 42 additions and 17 deletions

View File

@ -1001,27 +1001,52 @@ DWORD WINAPI GetLongPathNameA( LPCSTR shortpath, LPSTR longpath,
DWORD longlen ) DWORD longlen )
{ {
DOS_FULL_NAME full_name; DOS_FULL_NAME full_name;
char *p; char *p, *r, *ll, *ss;
char *longfilename;
DWORD shortpathlen;
if (!DOSFS_GetFullName( shortpath, TRUE, &full_name )) return 0; if (!DOSFS_GetFullName( shortpath, TRUE, &full_name )) return 0;
lstrcpynA( longpath, full_name.short_name, longlen ); lstrcpynA( longpath, full_name.short_name, longlen );
/* Do some hackery to get the long filename.
* FIXME: Would be better if it returned the /* Do some hackery to get the long filename. */
* long version of the directories too
*/ if (longpath) {
longfilename = strrchr(full_name.long_name, '/')+1; ss=longpath+strlen(longpath);
if (longpath != NULL) { ll=full_name.long_name+strlen(full_name.long_name);
if ((p = strrchr( longpath, '\\' )) != NULL) { p=NULL;
p++; while (ss>=longpath)
longlen -= (p-longpath); {
lstrcpynA( p, longfilename , longlen); /* FIXME: aren't we more paranoid, than needed? */
} while ((ss[0]=='\\') && (ss>=longpath)) ss--;
p=ss;
while ((ss[0]!='\\') && (ss>=longpath)) ss--;
if (ss>=longpath)
{
/* FIXME: aren't we more paranoid, than needed? */
while ((ll[0]=='/') && (ll>=full_name.long_name)) ll--;
while ((ll[0]!='/') && (ll>=full_name.long_name)) ll--;
if (ll<full_name.long_name)
{
ERR("Bad longname! (ss=%s ll=%s)\n This should never happen !\n"
,ss ,ll );
return 0;
}
}
}
/* FIXME: fix for names like "C:\\" (ie. with more '\'s) */
if (p && p[2])
{
p+=1;
if ((p-longpath)>0) longlen -= (p-longpath);
lstrcpynA( p, ll , longlen);
/* Now, change all '/' to '\' */
for (r=p; r<(p+longlen); r++ )
if (r[0]=='/') r[0]='\\';
return strlen(longpath) - strlen(p) + longlen;
}
} }
shortpathlen =
((strrchr( full_name.short_name, '\\' ) - full_name.short_name) + 1); return strlen(longpath);
return shortpathlen + strlen( longfilename );
} }