|
|
1.1 root 1: #include "frame.h"
2:
3: /*
4: * The code here and elsewhere requires that strings not be gcalloc()ed
5: */
6:
7: #define CHUNK 16
8: #define ROUNDUP(n) ((n+CHUNK)&~(CHUNK-1))
9: long clicks;
10: uchar *
11: allocstr(n)
12: unsigned n;
13: {
14: register uchar *p;
15: p=(uchar *)alloc(ROUNDUP(n));
16: if(p==0)
17: panic("out of memory");
18: return p;
19: }
20: insure(b, n)
21: register Box *b;
22: unsigned n;
23: {
24: register uchar *p;
25: if(b->len<0)
26: panic("insure");
27: if(ROUNDUP(b->len)>n) /* > guarantees room for terminal NUL */
28: return;
29: p=allocstr(n);
30: copystr(b->ptr, p);
31: freestr(b->ptr);
32: b->ptr=p;
33: }
34: freestr(s)
35: uchar *s;
36: {
37: free((char *)s);
38: }
39: copystr(from, to)
40: register uchar *from, *to;
41: {
42: do;while(*to++=*from++);
43: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.