Back to index

glibc  2.9
tst-inlcall.c
Go to the documentation of this file.
00001 /* Tester for calling inline string functions.
00002    Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _GNU_SOURCE
00021 #define _GNU_SOURCE
00022 #endif
00023 
00024 /* Make sure we test the optimized inline functions.  */
00025 #define __USE_STRING_INLINES       1
00026 
00027 #include <errno.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <strings.h>
00032 #include <fcntl.h>
00033 
00034 
00035 int
00036 main (void)
00037 {
00038   int status;
00039   int errors = 0;
00040   char buf1[1000];
00041   char *cp;
00042   char ch;
00043 
00044   cp = strcpy (buf1, "hello world");
00045   if (strcmp ("hello world", cp++) != 0)
00046     {
00047       puts ("strcmp test 1 failed");
00048       ++errors;
00049     }
00050 
00051   cp = buf1;
00052   if (strcmp (cp++, "hello world") != 0)
00053     {
00054       puts ("strcmp test 2 failed");
00055       ++errors;
00056     }
00057 
00058   ch = 'h';
00059   if (strchr ("hello world", ch++) == NULL)
00060     {
00061       puts ("strchr test 1 failed");
00062       ++errors;
00063     }
00064 
00065   const char * const hw = "hello world";
00066   if (strpbrk (hw, "o") - hw != 4)
00067     {
00068       puts ("strpbrk test 1 failed");
00069       ++errors;
00070     }
00071 
00072   if (errors == 0)
00073     {
00074       status = EXIT_SUCCESS;
00075       puts ("No errors.");
00076     }
00077   else
00078     {
00079       status = EXIT_FAILURE;
00080       printf ("%d errors.\n", errors);
00081     }
00082   return status;
00083 }