Annotation of researchv10no/cmd/odist/tar/sub.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <string.h>
        !             3: #include "misc.h"
        !             4: 
        !             5: void
        !             6: addsub(struct sub **sublistp, char *ostr, char *nstr)
        !             7: {
        !             8:        struct sub *nsub;
        !             9: 
        !            10:        nsub = xmalloc(sizeof (struct sub));
        !            11:        nsub->ostr = xstrdup(ostr);
        !            12:        nsub->nstr = xstrdup(nstr);
        !            13:        nsub->next = *sublistp;
        !            14:        *sublistp = nsub;
        !            15: }
        !            16: 
        !            17: int
        !            18: sub(struct sub **sublistp, int prefix, char str[], int maxlen)
        !            19: {
        !            20:        struct sub *sub;
        !            21:        int olen, nlen;
        !            22: 
        !            23:        for (sub = *sublistp; sub; sub = sub->next) {
        !            24:                olen = strlen(sub->ostr);
        !            25:                if (prefix && strncmp(str, sub->ostr, olen) == 0)
        !            26:                        break;
        !            27:                else if (!prefix && strcmp(str, sub->ostr))
        !            28:                        break;
        !            29:        }
        !            30:        if (!sub)
        !            31:                return 1;
        !            32:        nlen = strlen(sub->nstr);
        !            33:        if (strlen(str) + nlen - olen > maxlen)
        !            34:                return 0;
        !            35:        memmove(str + nlen, str + olen, strlen(str + olen) + 1);
        !            36:        strncpy(str, sub->nstr, nlen);
        !            37: }

unix.superglobalmegacorp.com

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