[ros-dev] [ros-diffs] [pschweitzer] 50867: [KERNEL32] Don't make GetBinaryTypeA() rely on Wine's strings conversions functions

Aleksey Bragin aleksey at reactos.org
Wed Feb 23 09:22:14 UTC 2011


This commit sounds like FilenameA2W is some evil we should get rid of  
as soon as possible, otherwise it takes over the world.

In fact, FilenameA2W is the same stuff which you just unwrapped, so  
instead of 1 line, there are 20 lines now. The only thing would be  
setting correct LastError, but for some reason I think Wine did it  
right too (they have tests).

In my opinion, it makes sense to either rewrite the buggy code (buggy  
being really buggy or questionable origin, if code comes from Wine it  
doesn't automatically mean it's buggy), or let the shared code be  
shared and just update it from the latest Wine.

WBR,
Aleksey Bragin.

On Feb 22, 2011, at 9:43 PM, pschweitzer at svn.reactos.org wrote:

> Author: pschweitzer
> Date: Tue Feb 22 18:43:38 2011
> New Revision: 50867
>
> URL: http://svn.reactos.org/svn/reactos?rev=50867&view=rev
> Log:
> [KERNEL32]
> Don't make GetBinaryTypeA() rely on Wine's strings conversions  
> functions
>
> Modified:
>     trunk/reactos/dll/win32/kernel32/file/bintype.c
>
> Modified: trunk/reactos/dll/win32/kernel32/file/bintype.c
> URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ 
> kernel32/file/bintype.c?rev=50867&r1=50866&r2=50867&view=diff
> ====================================================================== 
> ========
> --- trunk/reactos/dll/win32/kernel32/file/bintype.c [iso-8859-1]  
> (original)
> +++ trunk/reactos/dll/win32/kernel32/file/bintype.c [iso-8859-1]  
> Tue Feb 22 18:43:38 2011
> @@ -301,23 +301,43 @@
>   */
>  BOOL
>  WINAPI
> -GetBinaryTypeA (
> -    LPCSTR  lpApplicationName,
> -    LPDWORD lpBinaryType
> -    )
> +GetBinaryTypeA(IN LPCSTR lpApplicationName,
> +               OUT LPDWORD lpBinaryType)
>  {
> -  PWCHAR ApplicationNameW;
> -
> -  if(!lpApplicationName || !lpBinaryType)
> -  {
> -    SetLastError(ERROR_INVALID_PARAMETER);
> -    return FALSE;
> -  }
> -
> -  if (!(ApplicationNameW = FilenameA2W(lpApplicationName, FALSE)))
> -     return FALSE;
> -
> -  return GetBinaryTypeW(ApplicationNameW, lpBinaryType);
> +    ANSI_STRING ApplicationNameString;
> +    UNICODE_STRING ApplicationNameW;
> +    BOOL StringAllocated = FALSE, Result;
> +    NTSTATUS Status;
> +
> +    RtlInitAnsiString(&ApplicationNameString, lpApplicationName);
> +
> +    if (ApplicationNameString.Length * sizeof(WCHAR) >=  
> NtCurrentTeb()->StaticUnicodeString.MaximumLength)
> +    {
> +        StringAllocated = TRUE;
> +        Status = RtlAnsiStringToUnicodeString(&ApplicationNameW,  
> &ApplicationNameString, TRUE);
> +    }
> +    else
> +    {
> +        Status = RtlAnsiStringToUnicodeString(&(NtCurrentTeb()- 
> >StaticUnicodeString), &ApplicationNameString, FALSE);
> +    }
> +
> +    if (!NT_SUCCESS(Status))
> +    {
> +        BaseSetLastNTError(Status);
> +        return FALSE;
> +    }
> +
> +    if (StringAllocated)
> +    {
> +        Result = GetBinaryTypeW(ApplicationNameW.Buffer,  
> lpBinaryType);
> +        RtlFreeUnicodeString(&ApplicationNameW);
> +    }
> +    else
> +    {
> +        Result = GetBinaryTypeW(NtCurrentTeb()- 
> >StaticUnicodeString.Buffer, lpBinaryType);
> +    }
> +
> +    return Result;
>  }
>
>  /* EOF */
>
>




More information about the Ros-dev mailing list