tst-mbswcs6.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <errno.h>
  18. #include <locale.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <wchar.h>
  22. static int
  23. do_test (const char *loc)
  24. {
  25. char buf[100];
  26. size_t n;
  27. mbstate_t state;
  28. const char *nloc;
  29. int res;
  30. nloc = setlocale (LC_ALL, loc);
  31. if (nloc == NULL)
  32. {
  33. printf ("could not set locale \"%s\"\n", loc);
  34. return 1;
  35. }
  36. printf ("new locale: %s\n", nloc);
  37. memset (&state, '\0', sizeof (state));
  38. errno = 0;
  39. n = wcrtomb (buf, (wchar_t) -15l, &state);
  40. printf ("n = %zd, errno = %d (%s)\n", n, errno, strerror (errno));
  41. res = n != (size_t) -1 || errno != EILSEQ;
  42. if (res)
  43. puts ("*** FAIL");
  44. putchar ('\n');
  45. return res;
  46. }
  47. int
  48. main (void)
  49. {
  50. int res;
  51. res = do_test ("C");
  52. res |= do_test ("de_DE.ISO-8859-1");
  53. res |= do_test ("de_DE.UTF-8");
  54. res |= do_test ("en_US.ISO-8859-1");
  55. res |= do_test ("ja_JP.UTF-8");
  56. res |= do_test ("hr_HR.ISO-8859-2");
  57. //res |= do_test ("ru_RU.KOI8-R");
  58. return res;
  59. }