|
|
1.1 root 1: #
2:
3: /*
4: * Mail -- a mail program
5: *
6: * String allocation routines.
7: * Strings handed out here are reclaimed at the top of the command
8: * loop each time, so they need not be freed.
9: */
10:
11: #include "rcv.h"
12:
13: /*
14: * Allocate size more bytes of space and return the address of the
15: * first byte to the caller. An even number of bytes are always
16: * allocated so that the space will always be on a word boundary.
17: * The string spaces are of exponentially increasing size, to satisfy
18: * the occasional user with enormous string size requests.
19: */
20:
21: char *
22: salloc(size)
23: {
24: register char *t;
25: register int s;
26: register struct strings *sp;
27: int index;
28:
29: s = size;
30: s++;
31: s &= ~01;
32: index = 0;
33: for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
34: if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s)
35: break;
36: if (sp->s_nleft >= s)
37: break;
38: index++;
39: }
40: if (sp >= &stringdope[NSPACE])
41: panic("String too large");
42: if (sp->s_topFree == NOSTR) {
43: index = sp - &stringdope[0];
44: sp->s_topFree = (char *) calloc(STRINGSIZE << index,
45: (unsigned) 1);
46: if (sp->s_topFree == NOSTR) {
47: fprintf(stderr, "No room for space %d\n", index);
48: panic("Internal error");
49: }
50: sp->s_nextFree = sp->s_topFree;
51: sp->s_nleft = STRINGSIZE << index;
52: }
53: sp->s_nleft -= s;
54: t = sp->s_nextFree;
55: sp->s_nextFree += s;
56: return(t);
57: }
58:
59: /*
60: * Reset the string area to be empty.
61: * Called to free all strings allocated
62: * since last reset.
63: */
64:
65: sreset()
66: {
67: register struct strings *sp;
68: register int index;
69:
70: minit();
71: index = 0;
72: for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
73: if (sp->s_topFree == NOSTR)
74: continue;
75: sp->s_nextFree = sp->s_topFree;
76: sp->s_nleft = STRINGSIZE << index;
77: index++;
78: }
79: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.