FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/*
 * makequerydata - form a data buffer to be included with a query
 */
form a data buffer to be included with a query
form a data buffer to be included with a query
static void
makequerydata(
	struct varlist *vlist,
	size_t *datalen,
	char *data
	)
{
	register struct varlist *vl;
	register char *cp, *cpend;
	register size_t namelen, valuelen;
	register size_t totallen;
	cp = data;
	cpend = data + *datalen;
	for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) {
		namelen = strlen(vl->name);
		if (vl->value == 0)
			valuelen = 0;
		else
			valuelen = strlen(vl->value);
		totallen = namelen + valuelen + (valuelen != 0) + (cp != data);
		if (cp + totallen > cpend) {
		    fprintf(stderr, 
			    "***Ignoring variables starting with `%s'\n",
			    vl->name);
		    break;
		}
		if (cp != data)
			*cp++ = ',';
		memcpy(cp, vl->name, (size_t)namelen);
		cp += namelen;
		if (valuelen != 0) {
			*cp++ = '=';
			memcpy(cp, vl->value, (size_t)valuelen);
			cp += valuelen;
		}
	}
	*datalen = (size_t)(cp - data);
}
static void makequerydata ( struct varlist * vlist , size_t * datalen , char * data ) { register struct varlist * vl ; register char * cp , * cpend ; register size_t namelen , valuelen ; register size_t totallen ; cp = data ; cpend = data + * datalen ; for ( vl = vlist ; vl < vlist + MAXLIST && vl -> name != 0 ; vl ++ ) { namelen = strlen ( vl -> name ) ; if ( vl -> value == 0 ) valuelen = 0 ; else valuelen = strlen ( vl -> value ) ; totallen = namelen + valuelen + ( valuelen != 0 ) + ( cp != data ) ; if ( cp + totallen > cpend ) { fprintf ( stderr , " \n " , vl -> name ) ; break ; } if ( cp != data ) * cp ++ = ' ' ; memcpy ( cp , vl -> name , ( size_t ) namelen ) ; cp += namelen ; if ( valuelen != 0 ) { * cp ++ = ' ' ; memcpy ( cp , vl -> value , ( size_t ) valuelen ) ; cp += valuelen ; } } * datalen = ( size_t ) ( cp - data ) ; }
makequerydata - form a data buffer to be included with a query
makequerydata - form a data buffer to be included with a query