Introduction
Introduction Statistics Contact Development Disclaimer Help
frstr.c - sam - An updated version of the sam text editor.
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
frstr.c (771B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include <frame.h>
5
6 /*
7 * The code here and elsewhere requires that strings not be gcalloc()ed
8 */
9
10 #define CHUNK 16
11 #define ROUNDUP(n) ((n+CHUNK)&~(CHUNK-1))
12
13 uint8_t *
14 _frallocstr(unsigned n)
15 {
16 uint8_t *p;
17
18 p = malloc(ROUNDUP(n));
19 if(p == 0)
20 berror("out of memory");
21 return p;
22 }
23
24 void
25 _frinsure(Frame *f, int bn, unsigned n)
26 {
27 Frbox *b;
28 uint8_t *p;
29
30 b = &f->box[bn];
31 if(b->nrune < 0)
32 berror("_frinsure");
33 if(ROUNDUP(b->nrune) > n) /* > guarantees room for terminal NUL */
34 return;
35 p = _frallocstr(n);
36 b = &f->box[bn];
37 memmove(p, b->a.ptr, NBYTE(b)+1);
38 free(b->a.ptr);
39 b->a.ptr = p;
40 }
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.