Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>4 #include <mouse.h>5 #include <frame.h>7 #define CHUNK 168 #define ROUNDUP(n) ((n+CHUNK)&~(CHUNK-1))10 uchar *11 _frallocstr(Frame *f, unsigned n)12 {13 uchar *p;15 p = malloc(ROUNDUP(n));16 if(p == 0)17 drawerror(f->display, "out of memory");18 return p;19 }21 void22 _frinsure(Frame *f, int bn, unsigned n)23 {24 Frbox *b;25 uchar *p;27 b = &f->box[bn];28 if(b->nrune < 0)29 drawerror(f->display, "_frinsure");30 if(ROUNDUP(b->nrune) > n) /* > guarantees room for terminal NUL */31 return;32 p = _frallocstr(f, n);33 b = &f->box[bn];34 memmove(p, b->ptr, NBYTE(b)+1);35 free(b->ptr);36 b->ptr = p;37 }