tst-inlcall.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Tester for calling inline string functions.
  2. Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C 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. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _GNU_SOURCE
  16. #define _GNU_SOURCE
  17. #endif
  18. /* Make sure we test the optimized inline functions. */
  19. #define __USE_STRING_INLINES 1
  20. #include <errno.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <strings.h>
  25. #include <fcntl.h>
  26. int
  27. main (void)
  28. {
  29. int status;
  30. int errors = 0;
  31. char buf1[1000];
  32. char *cp;
  33. char ch;
  34. cp = strcpy (buf1, "hello world");
  35. if (strcmp ("hello world", cp++) != 0)
  36. {
  37. puts ("strcmp test 1 failed");
  38. ++errors;
  39. }
  40. cp = buf1;
  41. if (strcmp (cp++, "hello world") != 0)
  42. {
  43. puts ("strcmp test 2 failed");
  44. ++errors;
  45. }
  46. ch = 'h';
  47. if (strchr ("hello world", ch++) == NULL)
  48. {
  49. puts ("strchr test 1 failed");
  50. ++errors;
  51. }
  52. const char * const hw = "hello world";
  53. if (strpbrk (hw, "o") - hw != 4)
  54. {
  55. puts ("strpbrk test 1 failed");
  56. ++errors;
  57. }
  58. if (errors == 0)
  59. {
  60. status = EXIT_SUCCESS;
  61. puts ("No errors.");
  62. }
  63. else
  64. {
  65. status = EXIT_FAILURE;
  66. printf ("%d errors.\n", errors);
  67. }
  68. return status;
  69. }