comparison src/video/x11/SDL_x11video.c @ 4067:07d621a03a94 SDL-1.2

Use SDL C functions (fixes security warnings on OpenBSD)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 14 Jul 2007 21:09:54 +0000
parents 3f93ccc2c01e
children df2f562890a0
comparison
equal deleted inserted replaced
4066:58a5055da431 4067:07d621a03a94
436 SDL_IM = NULL; 436 SDL_IM = NULL;
437 } 437 }
438 438
439 /* Open an input method. */ 439 /* Open an input method. */
440 if (SDL_IM == NULL) { 440 if (SDL_IM == NULL) {
441 char *old_locale, *old_modifiers; 441 char *old_locale = NULL, *old_modifiers = NULL;
442 const char *p;
443 size_t n;
442 /* I'm not comfortable to do locale setup 444 /* I'm not comfortable to do locale setup
443 here. However, we need C library locale 445 here. However, we need C library locale
444 (and xlib modifiers) to be set based on the 446 (and xlib modifiers) to be set based on the
445 user's preference to use XIM, and many 447 user's preference to use XIM, and many
446 existing game programs doesn't take care of 448 existing game programs doesn't take care of
453 couldn't find better place to do the 455 couldn't find better place to do the
454 job... */ 456 job... */
455 457
456 /* Save the current (application program's) 458 /* Save the current (application program's)
457 locale settings. */ 459 locale settings. */
458 old_locale = setlocale(LC_ALL, NULL); 460 p = setlocale(LC_ALL, NULL);
459 old_modifiers = XSetLocaleModifiers(NULL); 461 if ( p ) {
460 if (old_locale == NULL || old_modifiers == NULL) { 462 n = SDL_strlen(p)+1;
461 /* The specs guarantee that the query 463 old_locale = SDL_stack_alloc(char, n);
462 calls to above functions never 464 if ( old_locale ) {
463 fail, so we should never come 465 SDL_strlcpy(old_locale, p, n);
464 here. */ 466 }
465 SDL_SetError("failed to retreive current locale settings"); 467 }
466 old_locale = NULL; 468 p = XSetLocaleModifiers(NULL);
467 old_modifiers = NULL; 469 if ( p ) {
468 } else { 470 n = SDL_strlen(p)+1;
469 /* Save retreived values in our own 471 old_modifiers = SDL_stack_alloc(char, n);
470 storage, since they may be 472 if ( old_modifiers ) {
471 overwritten by the successive calls 473 SDL_strlcpy(old_modifiers, p, n);
472 to 474 }
473 setlocale/XSetLocaleModifiers. */
474 char const *p;
475 p = old_locale;
476 old_locale = SDL_malloc(strlen(p) + 1);
477 strcpy(old_locale, p);
478 p = old_modifiers;
479 old_modifiers = SDL_malloc(strlen(p) + 1);
480 strcpy(old_modifiers, p);
481 } 475 }
482 476
483 /* Fetch the user's preferences and open the 477 /* Fetch the user's preferences and open the
484 input method with them. */ 478 input method with them. */
485 setlocale(LC_ALL, ""); 479 setlocale(LC_ALL, "");
487 SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname); 481 SDL_IM = XOpenIM(SDL_Display, NULL, classname, classname);
488 482
489 /* Restore the application's locale settings 483 /* Restore the application's locale settings
490 so that we don't break the application's 484 so that we don't break the application's
491 expected behaviour. */ 485 expected behaviour. */
492 if (old_locale != NULL && old_modifiers != NULL) { 486 if ( old_locale ) {
493 /* We need to restore the C library 487 /* We need to restore the C library
494 locale first, since the 488 locale first, since the
495 interpretation of the X modifier 489 interpretation of the X modifier
496 may depend on it. */ 490 may depend on it. */
497 setlocale(LC_ALL, old_locale); 491 setlocale(LC_ALL, old_locale);
498 SDL_free(old_locale); 492 SDL_stack_free(old_locale);
493 }
494 if ( old_modifiers ) {
499 XSetLocaleModifiers(old_modifiers); 495 XSetLocaleModifiers(old_modifiers);
500 SDL_free(old_modifiers); 496 SDL_stack_free(old_modifiers);
501 } 497 }
502 } 498 }
503 499
504 /* Create a new input context for the new window just created. */ 500 /* Create a new input context for the new window just created. */
505 if (SDL_IM == NULL) { 501 if (SDL_IM == NULL) {