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"
|
---|
25 | SIGNATURE_CHECK (strnlen, size_t, (char const *, size_t));
|
---|
26 |
|
---|
27 | #include <stdlib.h>
|
---|
28 |
|
---|
29 | #include "zerosize-ptr.h"
|
---|
30 | #include "macros.h"
|
---|
31 |
|
---|
32 | int
|
---|
33 | main (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 | }
|
---|