File: frstr.c

package info (click to toggle)
sam 4.3-18.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,440 kB
  • ctags: 1,662
  • sloc: ansic: 14,328; sh: 879; makefile: 205
file content (41 lines) | stat: -rw-r--r-- 703 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Copyright (c) 1992 AT&T - All rights reserved. */
#include <u.h>
#include <libc.h>
#include <libg.h>
#include <frame.h>

/*
 * The code here and elsewhere requires that strings not be gcalloc()ed
 */

#define	CHUNK	16
#define	ROUNDUP(n)	((n+CHUNK)&~(CHUNK-1))

uchar *
_frallocstr(unsigned n)
{
	uchar *p;

	p = malloc(ROUNDUP(n));
	if(p == 0)
		berror("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)
		berror("_frinsure");
	if(ROUNDUP(b->nrune) > n)	/* > guarantees room for terminal NUL */
		return;
	p = _frallocstr(n);
	b = &f->box[bn];
	memmove(p, b->a.ptr, NBYTE(b)+1);
	free(b->a.ptr);
	b->a.ptr = p;
}