Esempio n. 1
0
static void
file_init(struct file *f, const char *filename)
{
	struct varbuf usefilename = VARBUF_INIT;

	varbuf_add_str(&usefilename, instdir);
	varbuf_add_str(&usefilename, filename);
	varbuf_end_str(&usefilename);

	f->name = varbuf_detach(&usefilename);
	f->stat_state = FILE_STAT_INVALID;
}
Esempio n. 2
0
static void
test_varbuf_detach(void)
{
	struct varbuf vb;
	char *str;

	varbuf_init(&vb, 0);

	varbuf_add_buf(&vb, "1234567890", 10);

	str = varbuf_detach(&vb);

	test_mem(str, ==, "1234567890", 10);
	test_pass(vb.used == 0);
	test_pass(vb.size == 0);
	test_pass(vb.buf == NULL);

	free(str);
}
Esempio n. 3
0
char *
get_force_string(void)
{
	const struct forceinfo *fip;
	struct varbuf vb = VARBUF_INIT;

	for (fip = forceinfos; fip->name; fip++) {
		if ((enum force_flags)fip->flag == FORCE_ALL ||
		    (fip->flag & force_mask) != fip->flag ||
		    !in_force(fip->flag))
			continue;

		if (vb.used)
			varbuf_add_char(&vb, ',');
		varbuf_add_str(&vb, fip->name);
	}
	varbuf_end_str(&vb);

	return varbuf_detach(&vb);
}
Esempio n. 4
0
static char *
deb_field(const char *filename, const char *field)
{
	pid_t pid;
	int p[2];
	struct varbuf buf = VARBUF_INIT;
	char *end;

	m_pipe(p);

	pid = subproc_fork();
	if (pid == 0) {
		/* Child writes to pipe. */
		m_dup2(p[1], 1);
		close(p[0]);
		close(p[1]);

		execlp(BACKEND, BACKEND, "--field", filename, field, NULL);
		ohshite(_("unable to execute %s (%s)"),
		        _("package field value extraction"), BACKEND);
	}
	close(p[1]);

	/* Parant reads from pipe. */
	varbuf_reset(&buf);
	fd_vbuf_copy(p[0], &buf, -1, _("package field value extraction"));
	varbuf_end_str(&buf);

	close(p[0]);

	subproc_wait_check(pid, _("package field value extraction"), PROCPIPE);

	/* Trim down trailing junk. */
	for (end = buf.buf + strlen(buf.buf) - 1; end - buf.buf >= 1; end--)
		if (isspace(*end))
			*end = '\0';
		else
			break;

	return varbuf_detach(&buf);
}