* doc/gnulib-tool.texi (Initial import): Update to match current
[gnulib.git] / tests / test-memmem.c
1 /*
2  * Copyright (C) 2004, 2007 Free Software Foundation
3  * Written by Simon Josefsson
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.  */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <string.h>
26
27 int
28 main (int argc, char *argv[])
29 {
30   const char *big = "foo-bar-baz";
31   char *p;
32
33   p = memmem (big, "foo", strlen (big));
34   if (p != big)
35     {
36       fprintf (stderr, "memmem FAILURE 1\n");
37       return 1;
38     }
39
40   p = memmem (big, "baz", strlen (big));
41   if (p != big + strlen (big) - 3)
42     {
43       fprintf (stderr, "memmem FAILURE 2\n");
44       return 1;
45
46   p = memmem (big, "-", strlen (big));
47   if (p != big + 3)
48     {
49       fprintf (stderr, "memmem FAILURE 3\n");
50       return 1;
51     }
52
53   p = memmem (big, "baz", strlen (big) - 1);
54   if (p != NULL)
55     {
56       fprintf (stderr, "memmem FAILURE 4\n");
57       return 1;
58     }
59
60   return 0;
61 }