summaryrefslogtreecommitdiffstats
path: root/usr/klibc/tests/setjmptest.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/tests/setjmptest.c')
-rw-r--r--usr/klibc/tests/setjmptest.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/usr/klibc/tests/setjmptest.c b/usr/klibc/tests/setjmptest.c
new file mode 100644
index 0000000..fd9cb1c
--- /dev/null
+++ b/usr/klibc/tests/setjmptest.c
@@ -0,0 +1,37 @@
+/*
+ * setjmptest.c
+ */
+
+#include <stdio.h>
+#include <setjmp.h>
+
+static jmp_buf buf;
+
+void do_stuff(int v)
+{
+ printf("calling longjmp with %d... ", v + 1);
+ longjmp(buf, v + 1);
+}
+
+void recurse(int ctr, int v)
+{
+ if (ctr--)
+ recurse(ctr, v);
+ else
+ do_stuff(v);
+
+ printf("ERROR!\n"); /* We should never get here... */
+}
+
+int main(void)
+{
+ int v;
+
+ v = setjmp(buf);
+ printf("setjmp returned %d\n", v);
+
+ if (v < 256)
+ recurse(v, v);
+
+ return 0;
+}