src/locale/winrt/SDL_syslocale.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 20 May 2020 16:43:02 -0400
changeset 13837 c18c3084bd77
parent 13835 3f63f707ca4f
permissions -rw-r--r--
locale: Fixed compiler warning on WinRT.
icculus@13797
     1
/*
icculus@13797
     2
  Simple DirectMedia Layer
icculus@13797
     3
  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
icculus@13797
     4
icculus@13797
     5
  This software is provided 'as-is', without any express or implied
icculus@13797
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@13797
     7
  arising from the use of this software.
icculus@13797
     8
icculus@13797
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@13797
    10
  including commercial applications, and to alter it and redistribute it
icculus@13797
    11
  freely, subject to the following restrictions:
icculus@13797
    12
icculus@13797
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@13797
    14
     claim that you wrote the original software. If you use this software
icculus@13797
    15
     in a product, an acknowledgment in the product documentation would be
icculus@13797
    16
     appreciated but is not required.
icculus@13797
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@13797
    18
     misrepresented as being the original software.
icculus@13797
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@13797
    20
*/
icculus@13797
    21
icculus@13797
    22
#include <Windows.h>
icculus@13797
    23
icculus@13797
    24
#include "../../SDL_internal.h"
icculus@13797
    25
#include "../SDL_syslocale.h"
icculus@13797
    26
icculus@13797
    27
/*using namespace Windows::Graphics::Display;*/
icculus@13797
    28
#include <wchar.h>
icculus@13797
    29
icculus@13797
    30
void
icculus@13797
    31
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
icculus@13797
    32
{
icculus@13797
    33
    WCHAR wbuffer[128] = L"";
icculus@13797
    34
    int ret = 0;
icculus@13797
    35
icculus@13797
    36
    /* !!! FIXME: do we not have GetUserPreferredUILanguages on WinPhone or UWP? */
icculus@13797
    37
# if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
icculus@13835
    38
    ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SNAME, wbuffer, SDL_arraysize(wbuffer));
icculus@13797
    39
# else
icculus@13797
    40
    ret = GetSystemDefaultLocaleName(wbuffer, SDL_arraysize(wbuffer));
icculus@13797
    41
# endif
icculus@13797
    42
icculus@13797
    43
    if (ret > 0)
icculus@13797
    44
    {
icculus@13797
    45
        /* Need to convert LPWSTR to LPSTR, that is wide char to char. */
icculus@13797
    46
        int i;
icculus@13797
    47
icculus@13837
    48
        if ( ((size_t) ret) >= (buflen - 1) ) {
icculus@13797
    49
            ret = (int) (buflen - 1);
icculus@13797
    50
        }
icculus@13797
    51
        for (i = 0; i < ret; i++) {
icculus@13797
    52
            buf[i] = (char) wbuffer[i];  /* assume this was ASCII anyhow. */
icculus@13797
    53
        }
icculus@13797
    54
    }
icculus@13797
    55
}
icculus@13797
    56
icculus@13797
    57
/* vi: set ts=4 sw=4 expandtab: */
icculus@13797
    58