X11 msgbox: try to protect the existing setlocale() state.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 07 Dec 2012 23:26:28 -0500
changeset 67246c5ed0c4cc6d
parent 6723 7c464a9ecf48
child 6725 a7a99a9d419a
X11 msgbox: try to protect the existing setlocale() state.
src/video/x11/SDL_x11messagebox.c
     1.1 --- a/src/video/x11/SDL_x11messagebox.c	Fri Dec 07 20:00:42 2012 -0500
     1.2 +++ b/src/video/x11/SDL_x11messagebox.c	Fri Dec 07 23:26:28 2012 -0500
     1.3 @@ -654,14 +654,23 @@
     1.4  {
     1.5      int ret;
     1.6      SDL_MessageBoxDataX11 data;
     1.7 +    char *origlocale;
     1.8  
     1.9      SDL_zero(data);
    1.10  
    1.11 -    setlocale(LC_ALL, "");
    1.12 -
    1.13      if ( !SDL_X11_LoadSymbols() )
    1.14          return -1;
    1.15  
    1.16 +    origlocale = setlocale(LC_ALL, NULL);
    1.17 +    if (origlocale != NULL) {
    1.18 +        origlocale = SDL_strdup(origlocale);
    1.19 +        if (origlocale == NULL) {
    1.20 +            SDL_OutOfMemory();
    1.21 +            return -1;
    1.22 +        }
    1.23 +        setlocale(LC_ALL, "");
    1.24 +    }
    1.25 +
    1.26      /* This code could get called from multiple threads maybe? */
    1.27      XInitThreads();
    1.28  
    1.29 @@ -681,6 +690,12 @@
    1.30      }
    1.31  
    1.32      X11_MessageBoxShutdown( &data );
    1.33 +
    1.34 +    if (origlocale) {
    1.35 +        setlocale(LC_ALL, origlocale);
    1.36 +        SDL_free(origlocale);
    1.37 +    }
    1.38 +
    1.39      return ret;
    1.40  }
    1.41