L
luserXtrog
A little experiment.
Is this standard?
981(1)12:50 AM:~ 0> cat erh.c
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
enum e_err { noerror, bad, worse, yermom };
jmp_buf env;
void error(enum e_err errval) {
longjmp(env, errval);
}
void sigfpe_handle (int sig) {
error(worse);
}
void sigsegv_handle (int sig) {
error(yermom);
}
int somethingrisky(int i) {
if (i == 4) error(bad);
return somethingrisky(i+1);
}
int somethingstupid(int d) {
return 60/d;
}
int somethingtotallyretarded(char *buf) {
int i;
for (i=0;i<1000;i++) {
memcpy(buf+i*1000,"I claim this territory in the name of
Spain.",50);
}
}
int main() {
int err;
signal(SIGFPE, sigfpe_handle);
signal(SIGSEGV, sigsegv_handle);
if ( (err=setjmp(env)) == 0) {
somethingrisky(1);
somethingstupid(0);
printf("everything's ok\n");
} else switch (err) {
case bad: printf("it's bad!\n");
somethingstupid(0);
break;
case worse: printf("it's worse!\n");
somethingtotallyretarded(15);
break;
case yermom: printf("your mother has been called\n");
break;
}
return 0;
}
982(1)12:51 AM:~ 0> make erh
cc -g -Wall erh.c -o erh
erh.c: In function 'somethingtotallyretarded':
erh.c:36: warning: control reaches end of non-void function
erh.c: In function 'main':
erh.c:56: warning: passing argument 1 of 'somethingtotallyretarded'
makes pointer from integer without a cast
985(1)12:56 AM:~ 0> erh
it's bad!
it's worse!
your mother has been called
986(1)12:56 AM:~ 0> echo luser
Is this standard?
981(1)12:50 AM:~ 0> cat erh.c
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
enum e_err { noerror, bad, worse, yermom };
jmp_buf env;
void error(enum e_err errval) {
longjmp(env, errval);
}
void sigfpe_handle (int sig) {
error(worse);
}
void sigsegv_handle (int sig) {
error(yermom);
}
int somethingrisky(int i) {
if (i == 4) error(bad);
return somethingrisky(i+1);
}
int somethingstupid(int d) {
return 60/d;
}
int somethingtotallyretarded(char *buf) {
int i;
for (i=0;i<1000;i++) {
memcpy(buf+i*1000,"I claim this territory in the name of
Spain.",50);
}
}
int main() {
int err;
signal(SIGFPE, sigfpe_handle);
signal(SIGSEGV, sigsegv_handle);
if ( (err=setjmp(env)) == 0) {
somethingrisky(1);
somethingstupid(0);
printf("everything's ok\n");
} else switch (err) {
case bad: printf("it's bad!\n");
somethingstupid(0);
break;
case worse: printf("it's worse!\n");
somethingtotallyretarded(15);
break;
case yermom: printf("your mother has been called\n");
break;
}
return 0;
}
982(1)12:51 AM:~ 0> make erh
cc -g -Wall erh.c -o erh
erh.c: In function 'somethingtotallyretarded':
erh.c:36: warning: control reaches end of non-void function
erh.c: In function 'main':
erh.c:56: warning: passing argument 1 of 'somethingtotallyretarded'
makes pointer from integer without a cast
985(1)12:56 AM:~ 0> erh
it's bad!
it's worse!
your mother has been called
986(1)12:56 AM:~ 0> echo luser