locale.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include <features.h>
  18. #include "pthread.h"
  19. #include "internals.h"
  20. #include <locale.h>
  21. #include <assert.h>
  22. #include <stdlib.h>
  23. extern struct _pthread_descr_struct __pthread_initial_thread;
  24. __locale_t __curlocale(void)
  25. {
  26. pthread_descr self = thread_self();
  27. #ifdef NDEBUG
  28. return THREAD_GETMEM (self, locale);
  29. #else
  30. {
  31. __locale_t r = THREAD_GETMEM (self, locale);
  32. assert(r);
  33. return r;
  34. }
  35. #endif
  36. }
  37. __locale_t __curlocale_set(__locale_t newloc)
  38. {
  39. __locale_t oldloc;
  40. pthread_descr self = thread_self();
  41. oldloc = THREAD_GETMEM (self, locale);
  42. assert(newloc != LC_GLOBAL_LOCALE);
  43. assert(oldloc);
  44. THREAD_SETMEM (self, locale, newloc);
  45. return oldloc;
  46. }