From b5990708483a1fa452b3d4b6ed2bfa998deeeb39 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 30 Sep 2003 17:47:43 +0000 Subject: Initial import. --- src/libframe/frstr.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/libframe/frstr.c (limited to 'src/libframe/frstr.c') diff --git a/src/libframe/frstr.c b/src/libframe/frstr.c new file mode 100644 index 00000000..950b3e21 --- /dev/null +++ b/src/libframe/frstr.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +#define CHUNK 16 +#define ROUNDUP(n) ((n+CHUNK)&~(CHUNK-1)) + +uchar * +_frallocstr(Frame *f, unsigned n) +{ + uchar *p; + + p = malloc(ROUNDUP(n)); + if(p == 0) + drawerror(f->display, "out of memory"); + return p; +} + +void +_frinsure(Frame *f, int bn, unsigned n) +{ + Frbox *b; + uchar *p; + + b = &f->box[bn]; + if(b->nrune < 0) + drawerror(f->display, "_frinsure"); + if(ROUNDUP(b->nrune) > n) /* > guarantees room for terminal NUL */ + return; + p = _frallocstr(f, n); + b = &f->box[bn]; + memmove(p, b->ptr, NBYTE(b)+1); + free(b->ptr); + b->ptr = p; +} -- cgit v1.2.3