summaryrefslogtreecommitdiffstats
path: root/src/libframe/frstr.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-09-30 17:47:43 +0000
committerrsc <devnull@localhost>2003-09-30 17:47:43 +0000
commitb5990708483a1fa452b3d4b6ed2bfa998deeeb39 (patch)
tree9d2413286307f7e29a1906ebe4d1b59477ff886d /src/libframe/frstr.c
parent76193d7cb0457807b2f0b95f909ab5de19480cd7 (diff)
downloadplan9port-b5990708483a1fa452b3d4b6ed2bfa998deeeb39.tar.gz
plan9port-b5990708483a1fa452b3d4b6ed2bfa998deeeb39.zip
Initial import.
Diffstat (limited to 'src/libframe/frstr.c')
-rw-r--r--src/libframe/frstr.c37
1 files changed, 37 insertions, 0 deletions
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 <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <mouse.h>
+#include <frame.h>
+
+#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;
+}