tst-mbswcs6.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Test for invalid input to wcrtomb.
  2. Copyright (C) 2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <errno.h>
  17. #include <locale.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <wchar.h>
  21. static int
  22. do_test (const char *loc)
  23. {
  24. char buf[100];
  25. size_t n;
  26. mbstate_t state;
  27. const char *nloc;
  28. int res;
  29. nloc = setlocale (LC_ALL, loc);
  30. if (nloc == NULL)
  31. {
  32. printf ("could not set locale \"%s\"\n", loc);
  33. return 1;
  34. }
  35. printf ("new locale: %s\n", nloc);
  36. memset (&state, '\0', sizeof (state));
  37. errno = 0;
  38. n = wcrtomb (buf, (wchar_t) -15l, &state);
  39. printf ("n = %zd, errno = %d (%s)\n", n, errno, strerror (errno));
  40. res = n != (size_t) -1 || errno != EILSEQ;
  41. if (res)
  42. puts ("*** FAIL");
  43. putchar ('\n');
  44. return res;
  45. }
  46. int
  47. main (void)
  48. {
  49. int res;
  50. res = do_test ("C");
  51. res |= do_test ("de_DE.ISO-8859-1");
  52. res |= do_test ("de_DE.UTF-8");
  53. res |= do_test ("en_US.ISO-8859-1");
  54. res |= do_test ("ja_JP.UTF-8");
  55. res |= do_test ("hr_HR.ISO-8859-2");
  56. //res |= do_test ("ru_RU.KOI8-R");
  57. return res;
  58. }