Annotation of researchv10no/cmd/view2d/sys.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * A reasonable interface to the system calls
        !             3:  */
        !             4: #include <stdio.h>
        !             5: error(a, b, c, d, e)
        !             6:        char *a;
        !             7: {
        !             8:        extern int errno;
        !             9:        extern char *sys_errlist[];
        !            10:        extern int sys_nerr;
        !            11:        extern char *progname;
        !            12: 
        !            13:        fprintf(stderr, "%s: ", progname);
        !            14:        fprintf(stderr, a, b, c, d, e);
        !            15:        if(errno && errno<sys_nerr)
        !            16:                fprintf(stderr, ": %s\n", sys_errlist[errno]);
        !            17:        else
        !            18:                fprintf(stderr, "\n");
        !            19:        exit(1);
        !            20: }
        !            21: Read(f, a, n)
        !            22:        char *a;
        !            23: {
        !            24:        int nr, total=0;
        !            25:        while(total<n){
        !            26:                nr = read(f, a+total, n-total);
        !            27:                if(nr<0) error("read error");
        !            28:                if(nr==0) error("premature EOF");
        !            29:                total += nr;
        !            30:        }
        !            31: }
        !            32: EOFRead(f, a, n)
        !            33:        char *a;
        !            34: {
        !            35:        int nr, total=0;
        !            36:        while(total<n){
        !            37:                nr = read(f, a+total, n-total);
        !            38:                if(nr<0) error("read error");
        !            39:                if(nr==0){
        !            40:                        if(total>0) error("premature EOF");
        !            41:                        else return(0);
        !            42:                }
        !            43:                total += nr;
        !            44:        }
        !            45:        return(total);
        !            46: }
        !            47: Write(f, a, n)
        !            48:        char *a;
        !            49: {
        !            50:        int m;
        !            51:        if((m=write(f, a, n))!=n)
        !            52:                error("write error, wanted %d got %d", n, m);
        !            53: }
        !            54: long
        !            55: Lseek(f, n, w)
        !            56:        long n;
        !            57: {
        !            58:        long p, lseek();
        !            59:        if((p=lseek(f, n, w))==-1)
        !            60:                error("lseek error");
        !            61:        return(p);
        !            62: }
        !            63: Creat(f, m)
        !            64:        char *f;
        !            65: {
        !            66:        int fd=creat(f, m);
        !            67:        if(fd<0)
        !            68:                error("can't create %s", f);
        !            69:        return fd;
        !            70: }
        !            71: Open(f, m)
        !            72:        char *f;
        !            73: {
        !            74:        int fd=open(f, m);
        !            75:        if(fd<0)
        !            76:                error("can't open %s", f);
        !            77:        return fd;
        !            78: }
        !            79: char *
        !            80: Malloc(n)
        !            81:        unsigned n;
        !            82: {
        !            83:        char *malloc(), *p=malloc(n);
        !            84:        if(p==0)
        !            85:                error("malloc failed");
        !            86:        return p;
        !            87: }
        !            88: 
        !            89: 
        !            90: double
        !            91: pow2 ( v )
        !            92:   short v;
        !            93: {
        !            94:   /* this is only here because the system pow is so bad */
        !            95:   double s = 1.0;
        !            96:   while( v>0 ){ v--; s *= 2; }
        !            97:   while( v<0 ){ v++; s /= 2; }
        !            98:   return(s);
        !            99: }

unix.superglobalmegacorp.com

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