X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-c-stack.c;h=96ab152c04639507813515f4743bb31e2ae370d1;hb=2c64312ecca19a60629cb929c1ae759109c772b5;hp=bcf72adbdef9bbc901690f1755ae24b65b62a9f7;hpb=1eb850a182e6e5aa66d17d314b394e2ded30e2b5;p=gnulib.git diff --git a/tests/test-c-stack.c b/tests/test-c-stack.c index bcf72adbd..96ab152c0 100644 --- a/tests/test-c-stack.c +++ b/tests/test-c-stack.c @@ -22,6 +22,10 @@ #include #include #if HAVE_SETRLIMIT +/* At least FreeBSD 5.0 needs extra headers before + will compile. */ +# include +# include # include #endif @@ -37,30 +41,37 @@ } \ while (0) -static long -recurse (char *p) +char *program_name; + +static volatile int * +recurse_1 (volatile int n, volatile int *p) { - char array[500]; - array[0] = 1; - return *p + recurse (array); + if (n >= 0) + *recurse_1 (n + 1, p) += n; + return p; } -char *program_name; +static int +recurse (volatile int n) +{ + int sum = 0; + return *recurse_1 (n, &sum); +} int main (int argc, char **argv) { - program_name = argv[0]; #if HAVE_SETRLIMIT && defined RLIMIT_STACK - /* Before starting the endless recursion, try to be friendly to the - user's machine. On some Linux 2.2.x systems, there is no stack - limit for user processes at all. We don't want to kill such - systems. */ - struct rlimit rl; - rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ - setrlimit (RLIMIT_STACK, &rl); + /* Before starting the endless recursion, try to be friendly to the + user's machine. On some Linux 2.2.x systems, there is no stack + limit for user processes at all. We don't want to kill such + systems. */ + struct rlimit rl; + rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ + setrlimit (RLIMIT_STACK, &rl); #endif + program_name = argv[0]; if (c_stack_action (0) == 0) { if (1 < argc) @@ -68,8 +79,9 @@ main (int argc, char **argv) exit_failure = 77; ++*argv[argc]; /* Intentionally dereference NULL. */ } - return recurse ("\1"); + return recurse (0); } + fputs ("skipping test: ", stderr); perror ("c_stack_action"); return 77; }