Annotation of researchv10no/games/word_clout/regerror.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: regerror(s)
                      3:        char *s;
                      4: {
                      5:        char buf[132];
                      6: 
                      7:        strcpy(buf, "regerror: ");
                      8:        strcat(buf, s);
                      9:        strcat(buf, "\n");
                     10:        write(2, buf, strlen(buf));
                     11:        exit(1);
                     12: }
                     13: int storcnt;
                     14: static max;
                     15: char *MALLOC(x)
                     16: {
                     17:        int *p;
                     18:        if(x>max) {
                     19:                fprintf(stderr,"MALLOC(%d)\n",max=x);
                     20:        }
                     21:        p=(int*)malloc(x+3*sizeof*p);
                     22:        if(p) {
                     23:                storcnt+=*p=x;
                     24:                p[1]=-2*x;
                     25:                p[2+(x+7)/sizeof*p]=-3*x;
                     26:                return (char*)(p+2);
                     27:        }
                     28:        return 0;
                     29: }
                     30: FREE(p)
                     31: int *p;
                     32: {
                     33:        p-=2; storcnt-=*p;
                     34:        if(*p>max||*p<=0)ERR("big free",p);
                     35:        if(p[1]!=-2*p[0])ERR("free head scribble",p);
                     36:        if(p[2+(*p+7)/sizeof*p]!=-3**p)ERR("free tail scribble",p);
                     37:        free(p);
                     38: }
                     39: ERR(s,p)
                     40: char *s;
                     41: int *p;
                     42: {
                     43:        fprintf(stderr,"ERR: %s\n",s);
                     44:        fprintf(stderr,"p=%o\n",p);
                     45:        fprintf(stderr,"p[0]=%d\n",p);
                     46:        fprintf(stderr,"p[1]=%d\n",p[1]);
                     47:        fprintf(stderr,"p[2]='%s'\n",(char*)(p+2));
                     48:        fprintf(stderr,"p[trail]=%d",p[2+(*p+7)/sizeof*p]);
                     49:        fflush(stdout);
                     50:        abort();
                     51: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.