tst-inlcall.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _GNU_SOURCE
  17. #define _GNU_SOURCE
  18. #endif
  19. /* Make sure we test the optimized inline functions. */
  20. #define __USE_STRING_INLINES 1
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <strings.h>
  26. #include <fcntl.h>
  27. int
  28. main (void)
  29. {
  30. int status;
  31. int errors = 0;
  32. char buf1[1000];
  33. char *cp;
  34. char ch;
  35. cp = strcpy (buf1, "hello world");
  36. if (strcmp ("hello world", cp++) != 0)
  37. {
  38. puts ("strcmp test 1 failed");
  39. ++errors;
  40. }
  41. cp = buf1;
  42. if (strcmp (cp++, "hello world") != 0)
  43. {
  44. puts ("strcmp test 2 failed");
  45. ++errors;
  46. }
  47. ch = 'h';
  48. if (strchr ("hello world", ch++) == NULL)
  49. {
  50. puts ("strchr test 1 failed");
  51. ++errors;
  52. }
  53. const char * const hw = "hello world";
  54. if (strpbrk (hw, "o") - hw != 4)
  55. {
  56. puts ("strpbrk test 1 failed");
  57. ++errors;
  58. }
  59. if (errors == 0)
  60. {
  61. status = EXIT_SUCCESS;
  62. puts ("No errors.");
  63. }
  64. else
  65. {
  66. status = EXIT_FAILURE;
  67. printf ("%d errors.\n", errors);
  68. }
  69. return status;
  70. }