Exemple #1
0
/*
 *  parse a command written to a device
 */
Cmdbuf*
parsecmd(char *p, int n)
{
	Cmdbuf *cb;
	int nf;
	char *sp;

	nf = ncmdfield(p, n);

	/* allocate Cmdbuf plus string pointers plus copy of string including \0 */
	sp = emalloc9p(sizeof(*cb) + nf * sizeof(char*) + n + 1);
	cb = (Cmdbuf*)sp;
	cb->f = (char**)(&cb[1]);
	cb->buf = (char*)(&cb->f[nf]);

	memmove(cb->buf, p, n);

	/* dump new line and null terminate */
	if(n > 0 && cb->buf[n-1] == '\n')
		n--;
	cb->buf[n] = '\0';

	cb->nf = tokenize(cb->buf, cb->f, nf-1);
	cb->f[cb->nf] = nil;

	return cb;
}
Exemple #2
0
/*
 *  parse a command written to a device
 */
struct cmdbuf *parsecmd(char *p, int n)
{
	ERRSTACK(1);
	struct cmdbuf *volatile cb;
	int nf;
	char *sp;

	nf = ncmdfield(p, n);

	/* allocate Cmdbuf plus string pointers plus copy of string including \0 */
	sp = kzmalloc(sizeof(*cb) + nf * sizeof(char *) + n + 1, 0);
	cb = (struct cmdbuf *)sp;
	cb->f = (char **)(&cb[1]);
	cb->buf = (char *)(&cb->f[nf]);

	if (current != NULL && waserror()) {
		kfree(cb);
		nexterror();
	}
	memmove(cb->buf, p, n);
	if (current != NULL)
		poperror();

	/* dump new line and null terminate */
	if (n > 0 && cb->buf[n - 1] == '\n')
		n--;
	cb->buf[n] = '\0';

	cb->nf = tokenize(cb->buf, cb->f, nf - 1);
	cb->f[cb->nf] = NULL;

	return cb;
}