[PATCH v6 4/4] ntdll: Allow renaming a file/directory to a different casing of itself.

Gabriel Ivăncescu gabrielopcode at gmail.com
Fri Apr 23 10:48:22 CDT 2021


On 23/04/2021 13:44, Rémi Bernon wrote:
> On 4/22/21 3:00 PM, Gabriel Ivăncescu wrote:
>> +/***********************************************************************
>> + *           nt_to_unix_file_name_with_casing
>> + *
>> + * Same as nt_to_unix_file_name, but additionally return unix file name
>> + * without path, with the original casing from the NT file name.
>> + */
>> +static NTSTATUS nt_to_unix_file_name_with_casing( const 
>> OBJECT_ATTRIBUTES *attr, char **name_ret,
>> +                                                  char **casing_ret, 
>> UINT disposition )
>> +{
>> +    const WCHAR *nt_filename = attr->ObjectName->Buffer + 
>> attr->ObjectName->Length / sizeof(WCHAR);
>> +    NTSTATUS status;
>> +    char *casing;
>> +    int len;
>> +
>> +    /* NT name may not be NUL terminated; look for last \ character */
>> +    for (; nt_filename != attr->ObjectName->Buffer; nt_filename--)
>> +        if (nt_filename[-1] == '\\')
>> +            break;
>> +    len = attr->ObjectName->Buffer + attr->ObjectName->Length / 
>> sizeof(WCHAR) - nt_filename;
>> +
> 
> Nitpick: You could make it a bit less verbose by using len to store
> 
>    attr->ObjectName->Length / sizeof(WCHAR)
> 
> instead of duplicating it here and above (initializing nt_filename in 
> the for, maybe).
> 
>> +    if (!(casing = malloc( len * 3 ))) return STATUS_NO_MEMORY;
>> +
>> +    status = nt_to_unix_file_name( attr, name_ret, disposition );
>> +    if (status != STATUS_SUCCESS && status != STATUS_NO_SUCH_FILE)
>> +    {
>> +        free(casing);
> 
> Nitpick: it should probably be "free( casing )" to be consistent.
> 
>> +        return status;
>> +    }
>> +
>> +    len = ntdll_wcstoumbs( nt_filename, len, casing, len * 3, TRUE );
>> +    if (len > 0)
>> +        casing[len] = 0;
> 
> Not a nitpick: we probably need +1 for the zero-termination in the 
> malloc for the worst case?
> 
> Otherwise I think it looks nice.

Right, sorry for the mistake, will resend shortly.



More information about the wine-devel mailing list