mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
simplified strcatf() with new macro strf()
This commit is contained in:
parent
5d5b36cd76
commit
433c65e717
5 changed files with 10 additions and 10 deletions
|
@ -93,10 +93,13 @@ double randf();
|
|||
char * strcatf(char **dest, const char *fmt, ...)
|
||||
__attribute__ ((format(printf, 2, 3)));
|
||||
|
||||
/** Variadic version of strcatv() */
|
||||
/** Variadic version of strcatf() */
|
||||
char * vstrcatf(char **dest, const char *fmt, va_list va)
|
||||
__attribute__ ((format(printf, 2, 0)));
|
||||
|
||||
/** Format string like strcatf() just starting with empty string */
|
||||
#define strf(fmt, ...) strcatf(&(void *) { NULL }, fmt, ##__VA_ARGS__)
|
||||
|
||||
/** Format a struct timespec date similar to strftime() */
|
||||
int strftimespec(char *s, size_t max, const char *format, struct timespec *ts)
|
||||
__attribute__ ((format(strftime, 3, 0)));
|
||||
|
|
|
@ -100,16 +100,15 @@ int gtfpga_parse(struct node *n, config_setting_t *cfg)
|
|||
char * gtfpga_print(struct node *n)
|
||||
{
|
||||
struct gtfpga *g = n->_vd;
|
||||
char *buf = NULL;
|
||||
|
||||
if (g->dev) {
|
||||
return strcatf(&buf, "rate=%.1f slot=%04"PRIx16":%02"PRIx8":%02"PRIx8".%"PRIx8
|
||||
return strf("rate=%.1f slot=%04"PRIx16":%02"PRIx8":%02"PRIx8".%"PRIx8
|
||||
" id=%04"PRIx16":%04"PRIx16" class=%04"PRIx16" irq=%d (%s)", g->rate,
|
||||
g->dev->domain, g->dev->bus, g->dev->dev, g->dev->func, g->dev->vendor_id, g->dev->device_id,
|
||||
g->dev->device_class, g->dev->irq, g->name);
|
||||
}
|
||||
else {
|
||||
return strcatf(&buf, "rate=%.1f slot=%02"PRIx8":%02"PRIx8".%"PRIx8" id=%04"PRIx16":%04"PRIx16, g->rate,
|
||||
return strf("rate=%.1f slot=%02"PRIx8":%02"PRIx8".%"PRIx8" id=%04"PRIx16":%04"PRIx16, g->rate,
|
||||
g->filter.bus, g->filter.device, g->filter.func,
|
||||
g->filter.vendor, g->filter.device);
|
||||
}
|
||||
|
|
|
@ -472,9 +472,8 @@ int ngsi_parse(struct node *n, config_setting_t *cfg)
|
|||
char * ngsi_print(struct node *n)
|
||||
{
|
||||
struct ngsi *i = n->_vd;
|
||||
char *buf = NULL;
|
||||
|
||||
return strcatf(&buf, "endpoint=%s, timeout=%.3f secs, #mappings=%zu",
|
||||
return strf("endpoint=%s, timeout=%.3f secs, #mappings=%zu",
|
||||
i->endpoint, i->timeout, list_length(&i->mapping));
|
||||
}
|
||||
|
||||
|
|
|
@ -143,11 +143,10 @@ int opal_parse(struct node *n, config_setting_t *cfg)
|
|||
char * opal_print(struct node *n)
|
||||
{
|
||||
struct opal *o = n->_vd;
|
||||
char *buf = NULL;
|
||||
|
||||
/** @todo: Print send_params, recv_params */
|
||||
|
||||
return strcatf(&buf, "send_id=%u, recv_id=%u, reply=%u",
|
||||
return strf("send_id=%u, recv_id=%u, reply=%u",
|
||||
o->send_id, o->recv_id, o->reply);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ int socket_deinit()
|
|||
char * socket_print(struct node *n)
|
||||
{
|
||||
struct socket *s = n->_vd;
|
||||
char *layer = NULL, *buf = NULL;
|
||||
char *layer = NULL, *buf;
|
||||
|
||||
switch (s->layer) {
|
||||
case LAYER_UDP: layer = "udp"; break;
|
||||
|
@ -107,7 +107,7 @@ char * socket_print(struct node *n)
|
|||
char *local = socket_print_addr((struct sockaddr *) &s->local);
|
||||
char *remote = socket_print_addr((struct sockaddr *) &s->remote);
|
||||
|
||||
strcatf(&buf, "layer=%s, local=%s, remote=%s", layer, local, remote);
|
||||
buf = strf("layer=%s, local=%s, remote=%s", layer, local, remote);
|
||||
|
||||
free(local);
|
||||
free(remote);
|
||||
|
|
Loading…
Add table
Reference in a new issue