VirtualBox

source: kBuild/vendor/grep/3.7/gnulib-tests/test-c-stack.c

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1/* Test of c-stack module.
2 Copyright (C) 2002, 2004, 2006, 2008-2021 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17#include <config.h>
18
19#include "c-stack.h"
20
21#include "exitfail.h"
22#include <stdio.h>
23#if HAVE_SETRLIMIT
24/* At least FreeBSD 5.0 needs extra headers before <sys/resource.h>
25 will compile. */
26# include <sys/types.h>
27# include <sys/time.h>
28# include <sys/resource.h>
29#endif
30
31#include "macros.h"
32
33static volatile int *
34recurse_1 (volatile int n, volatile int *p)
35{
36 if (n >= 0)
37 *recurse_1 (n + 1, p) += n;
38 return p;
39}
40
41static int
42recurse (volatile int n)
43{
44 int sum = 0;
45 return *recurse_1 (n, &sum);
46}
47
48int
49main (int argc, char **argv)
50{
51#if HAVE_SETRLIMIT && defined RLIMIT_STACK
52 /* Before starting the endless recursion, try to be friendly to the
53 user's machine. On some Linux 2.2.x systems, there is no stack
54 limit for user processes at all. We don't want to kill such
55 systems. */
56 struct rlimit rl;
57 rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
58 setrlimit (RLIMIT_STACK, &rl);
59#endif
60
61 if (c_stack_action (NULL) == 0)
62 {
63 if (1 < argc)
64 {
65 exit_failure = 77;
66 ++*argv[argc]; /* Intentionally dereference NULL. */
67 }
68 return recurse (0);
69 }
70 fputs ("skipping test: ", stderr);
71 perror ("c_stack_action");
72 return 77;
73}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette