Annotation of researchv10no/lbin/mailx/stralloc.c, revision 1.1

1.1     ! root        1: #ident "@(#)stralloc.c 1.3 'attmail mail(1) command'"
        !             2: #ident "@(#)mailx:stralloc.c   1.3.1.1"
        !             3: /*     Copyright (c) 1984 AT&T */
        !             4: /*       All Rights Reserved   */
        !             5: 
        !             6: /*     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T     */
        !             7: /*     The copyright notice above does not evidence any        */
        !             8: /*     actual or intended publication of such source code.     */
        !             9: 
        !            10: #ident "@(#)mailx:stralloc.c   1.3"
        !            11: 
        !            12: /*
        !            13:  * mailx -- a modified version of a University of California at Berkeley
        !            14:  *     mail program
        !            15:  *
        !            16:  * Memory allocation routines.
        !            17:  * Memory handed out here are reclaimed at the top of the command
        !            18:  * loop each time, so they need not be freed.
        !            19:  */
        !            20: 
        !            21: #include "rcv.h"
        !            22: 
        !            23: /*
        !            24:  * Allocate size more bytes of space and return the address of the
        !            25:  * first byte to the caller.  An even number of bytes are always
        !            26:  * allocated so that the space will always be on a word boundary.
        !            27:  * The string spaces are of exponentially increasing size, to satisfy
        !            28:  * the occasional user with enormous string size requests.
        !            29:  */
        !            30: 
        !            31: VOID *
        !            32: salloc(size)
        !            33:        unsigned size;
        !            34: {
        !            35:        register char *t;
        !            36:        register unsigned s;
        !            37:        register struct strings *sp;
        !            38:        int index;
        !            39: 
        !            40:        s = size;
        !            41:        s += 3;         /* 3b's need alignment on quad boundary */
        !            42:        s &= ~03;
        !            43:        index = 0;
        !            44:        for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
        !            45:                if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s)
        !            46:                        break;
        !            47:                if (sp->s_nleft >= s)
        !            48:                        break;
        !            49:                index++;
        !            50:        }
        !            51:        if (sp >= &stringdope[NSPACE])
        !            52:                panic("String too large");
        !            53:        if (sp->s_topFree == NOSTR) {
        !            54:                index = sp - &stringdope[0];
        !            55:                sp->s_topFree = (char *) calloc(STRINGSIZE << index,
        !            56:                    (unsigned) 1);
        !            57:                if (sp->s_topFree == NOSTR) {
        !            58:                        fprintf(stderr, "No room for space %d\n", index);
        !            59:                        panic("Internal error");
        !            60:                }
        !            61:                sp->s_nextFree = sp->s_topFree;
        !            62:                sp->s_nleft = STRINGSIZE << index;
        !            63:        }
        !            64:        sp->s_nleft -= s;
        !            65:        t = sp->s_nextFree;
        !            66:        sp->s_nextFree += s;
        !            67:        return(t);
        !            68: }
        !            69: 
        !            70: /*
        !            71:  * Reallocate size bytes of space and return the address of the
        !            72:  * first byte to the caller.  The old data is copied into the new area.
        !            73:  */
        !            74: 
        !            75: VOID *
        !            76: srealloc(optr, size)
        !            77:        VOID *optr;
        !            78:        unsigned size;
        !            79: {
        !            80:        VOID *nptr = salloc(size);
        !            81:        if (nptr)
        !            82:                memcpy(nptr, optr, size);
        !            83:        return nptr;
        !            84: }
        !            85: 
        !            86: /*
        !            87:  * Reset the string area to be empty.
        !            88:  * Called to free all strings allocated
        !            89:  * since last reset.
        !            90:  */
        !            91: void
        !            92: sreset()
        !            93: {
        !            94:        register struct strings *sp;
        !            95:        register int index;
        !            96: 
        !            97:        if (noreset)
        !            98:                return;
        !            99:        minit();
        !           100:        index = 0;
        !           101:        for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
        !           102:                if (sp->s_topFree == NOSTR)
        !           103:                        continue;
        !           104:                sp->s_nextFree = sp->s_topFree;
        !           105:                sp->s_nleft = STRINGSIZE << index;
        !           106:                index++;
        !           107:        }
        !           108: }

unix.superglobalmegacorp.com

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