コード例 #1
0
ファイル: cgfs.c プロジェクト: pombredanne/lxcfs
static void append_line(char **contents, size_t *len, char *line, ssize_t linelen)
{
	size_t newlen = *len + linelen;
	dorealloc(contents, *len, newlen + 1);
	memcpy(*contents + *len, line, linelen+1);
	*len = newlen;
}
コード例 #2
0
ファイル: lex.c プロジェクト: AustenConrad/plan-9
int
fillbuf(Source *s)
{
	int n;

	while((char *)s->inl+s->ins/8 > (char *)s->inb+s->ins) {
		int l = s->inl - s->inb;
		int p = s->inp - s->inb;
		if(l < 0) 
			error(FATAL, "negative end of input!?");
		if(p < 0)
			error(FATAL, "negative input pointer!?");
		/* double the buffer size and try again */
		s->ins *= 2;
		s->inb = dorealloc(s->inb, s->ins);
		s->inl = s->inb + l;
		s->inp = s->inb + p;
	}
	if (s->fd<0 || (n=read(s->fd, (char *)s->inl, s->ins/8)) <= 0)
		n = 0;
	if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
		*s->inp = EOFC;
	s->inl += n;
	s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOB;
	if (n==0) {
		s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOFC;
		return EOF;
	}
	return 0;
}
コード例 #3
0
ファイル: inode.c プロジェクト: cse451/os161
/*
 * Add an entry to the inode table, realloc'ing it if needed.
 */
static
void
inode_addtable(uint32_t ino, int type)
{
	unsigned newmax;

	assert(ninodes <= maxinodes);
	if (ninodes == maxinodes) {
		newmax = maxinodes ? maxinodes * 2 : 4;
		inodes = dorealloc(inodes, maxinodes * sizeof(inodes[0]),
				   newmax * sizeof(inodes[0]));
		maxinodes = newmax;
	}
	inodes[ninodes].ino = ino;
	inodes[ninodes].linkcount = 0;
	inodes[ninodes].visited = 0;
	inodes[ninodes].type = type;
	ninodes++;
	inodes_sorted = 0;
}
コード例 #4
0
ファイル: output.c プロジェクト: pathscale/tradcpp
void
output(const char *buf, size_t len)
{
	size_t oldmax;

	if (linebufpos + len > linebufmax) {
		oldmax = linebufmax;
		if (linebufmax == 0) {
			linebufmax = 64;
		}
		while (linebufpos + len > linebufmax) {
			linebufmax *= 2;
		}
		linebuf = dorealloc(linebuf, oldmax, linebufmax);
	}

	memcpy(linebuf + linebufpos, buf, len);
	linebufpos += len;

	if (len == 1 && buf[0] == '\n') {
		filter_output(linebuf, linebufpos);
		linebufpos = 0;
	}
}