Back to index

glibc  2.9
setjmp.c
Go to the documentation of this file.
00001 #include <setjmp.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 
00005 jmp_buf main_loop;
00006 
00007 void 
00008 abort_to_main_loop (int status)
00009 {
00010   longjmp (main_loop, status);
00011 }
00012 
00013 int
00014 main (void)
00015 {
00016   while (1)
00017     if (setjmp (main_loop))
00018       puts ("Back at main loop....");
00019     else
00020       do_command ();
00021 }
00022 
00023 
00024 void 
00025 do_command (void)
00026 {
00027   char buffer[128];
00028   if (fgets (buffer, 128, stdin) == NULL)
00029     abort_to_main_loop (-1);
00030   else
00031     exit (EXIT_SUCCESS);
00032 }