Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_fixcpp/sys/src/libString/s_grow.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include "String.h"
4
 
5
/* grow a String's allocation by at least `incr' bytes */
6
extern String*
7
s_grow(String *s, int incr)	
8
{
9
	char *cp;
10
	int size;
11
 
12
	if(s->fixed)
13
		sysfatal("s_grow of constant string");
14
	s = s_unique(s);
15
 
16
	/*
17
	 *  take a larger increment to avoid mallocing too often
18
	 */
19
	size = s->end-s->base;
20
	if(size/2 < incr)
21
		size += incr;
22
	else
23
		size += size/2;
24
 
25
	cp = realloc(s->base, size);
26
	if (cp == 0)
27
		sysfatal("s_grow: %r");
28
	s->ptr = (s->ptr - s->base) + cp;
29
	s->end = cp + size;
30
	s->base = cp;
31
 
32
	return s;
33
}
34