source: diffutils/vendor/current/gnulib-tests/test-strnlen.c@ 530

Last change on this file since 530 was 530, checked in by Yuri Dario, 12 years ago

diffutils: initial vendor import of diffutils 3.2.0.

File size: 1.8 KB
Line 
1/* -*- buffer-read-only: t -*- vi: set ro: */
2/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3/*
4 * Copyright (C) 2010-2011 Free Software Foundation, Inc.
5 * Written by Eric Blake
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include <config.h>
21
22#include <string.h>
23
24#include "signature.h"
25SIGNATURE_CHECK (strnlen, size_t, (char const *, size_t));
26
27#include <stdlib.h>
28
29#include "zerosize-ptr.h"
30#include "macros.h"
31
32int
33main (void)
34{
35 size_t i;
36 char *page_boundary = (char *) zerosize_ptr ();
37 if (!page_boundary)
38 {
39 page_boundary = malloc (0x1000);
40 ASSERT (page_boundary);
41 page_boundary += 0x1000;
42 }
43
44 /* Basic behavior tests. */
45 ASSERT (strnlen ("a", 0) == 0);
46 ASSERT (strnlen ("a", 1) == 1);
47 ASSERT (strnlen ("a", 2) == 1);
48 ASSERT (strnlen ("", 0x100000) == 0);
49
50 /* Memory fence and alignment testing. */
51 for (i = 0; i < 512; i++)
52 {
53 char *start = page_boundary - i;
54 size_t j = i;
55 memset (start, 'x', i);
56 do
57 {
58 if (i != j)
59 {
60 start[j] = 0;
61 ASSERT (strnlen (start, i + j) == j);
62 }
63 ASSERT (strnlen (start, i) == j);
64 ASSERT (strnlen (start, j) == j);
65 }
66 while (j--);
67 }
68
69 return 0;
70}
Note: See TracBrowser for help on using the repository browser.