locale.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2003 Manuel Novoa III
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the Free
  15. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #define _GNU_SOURCE
  18. #include <features.h>
  19. #include "pthread.h"
  20. #include "internals.h"
  21. #include <locale.h>
  22. #include <assert.h>
  23. #include <stdlib.h>
  24. extern struct _pthread_descr_struct __pthread_initial_thread;
  25. __locale_t __curlocale(void)
  26. {
  27. pthread_descr self = thread_self();
  28. #ifdef NDEBUG
  29. return THREAD_GETMEM (self, locale);
  30. #else
  31. {
  32. __locale_t r = THREAD_GETMEM (self, locale);
  33. assert(r);
  34. return r;
  35. }
  36. #endif
  37. }
  38. __locale_t __curlocale_set(__locale_t newloc)
  39. {
  40. __locale_t oldloc;
  41. pthread_descr self = thread_self();
  42. oldloc = THREAD_GETMEM (self, locale);
  43. assert(newloc != LC_GLOBAL_LOCALE);
  44. assert(oldloc);
  45. THREAD_SETMEM (self, locale, newloc);
  46. return oldloc;
  47. }