Annotation of researchv9/jtools/src/sunlib/muxbuf.c, revision 1.1

1.1     ! root        1: #include "jerq.h"
        !             2: #ifdef SUNTOOLS
        !             3: static char *buffile = "/tmp/muxbuf";
        !             4: #include <sys/file.h>
        !             5: #endif SUNTOOLS
        !             6: 
        !             7: typedef struct String{
        !             8:        char *s;        /* pointer to string */
        !             9:        short n;        /* number used, no terminal null */
        !            10:        short size;     /* size of allocated area */
        !            11: } String;
        !            12: 
        !            13: getmuxbuf (pmb)
        !            14: String *pmb;
        !            15: {
        !            16:        char *ans;
        !            17:        int n;
        !            18: 
        !            19: #ifdef X11
        !            20:        ans = XFetchBytes(dpy, &n);
        !            21: #endif X11
        !            22: #ifdef SUNTOOLS
        !            23: #define BSIZE 4096
        !            24:        char buffer[BSIZE];
        !            25:        int fd;
        !            26: 
        !            27:        fd = open(buffile, O_RDONLY);
        !            28:        if (fd < 0)
        !            29:                return;
        !            30:        n = read(fd, buffer, BSIZE);
        !            31:        close(fd);
        !            32:        if (n < 0)
        !            33:                return;
        !            34:        ans = buffer;
        !            35: #endif SUNTOOLS
        !            36:        if (pmb->size < (n+1)) {
        !            37:                pmb->size = n+1;
        !            38:                gcalloc(pmb->size, &(pmb->s));
        !            39:        }
        !            40:        pmb->n = n;
        !            41:        strncpy(pmb->s, ans, n+1);
        !            42: #ifdef X11
        !            43:        free(ans);
        !            44: #endif X11
        !            45: }
        !            46: 
        !            47: setmuxbuf(pmb)
        !            48: String *pmb;
        !            49: {
        !            50: #ifdef X11
        !            51:        XStoreBytes(dpy, pmb->s, pmb->n);
        !            52: #endif X11
        !            53: #ifdef SUNTOOLS
        !            54:        int fd = open(buffile, O_WRONLY|O_CREAT|O_TRUNC, 0666);
        !            55:        if (fd < 0)
        !            56:                return;
        !            57:        write(fd, pmb->s, pmb->n);
        !            58:        close(fd);
        !            59: #endif SUNTOOLS
        !            60: }

unix.superglobalmegacorp.com

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