drivers: Use g_strdup_printf() where possible.
This commit is contained in:
parent
8ebad34370
commit
d2391b5453
|
@ -481,7 +481,6 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct scope_state *state;
|
struct scope_state *state;
|
||||||
const struct scope_config *config;
|
const struct scope_config *config;
|
||||||
|
|
||||||
int tmp;
|
int tmp;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
float tmp_float;
|
float tmp_float;
|
||||||
|
@ -635,7 +634,6 @@ SR_PRIV void hmo_scope_state_free(struct scope_state *state)
|
||||||
|
|
||||||
SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
|
SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
char tmp[25];
|
|
||||||
int model_index;
|
int model_index;
|
||||||
unsigned int i, j, group;
|
unsigned int i, j, group;
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
|
@ -684,11 +682,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
/* Add digital channel groups. */
|
/* Add digital channel groups. */
|
||||||
for (i = 0; i < scope_models[model_index].digital_pods; i++) {
|
for (i = 0; i < scope_models[model_index].digital_pods; i++) {
|
||||||
g_snprintf(tmp, 25, "POD%d", i);
|
|
||||||
|
|
||||||
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
|
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
|
||||||
|
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i);
|
||||||
devc->digital_groups[i]->name = g_strdup(tmp);
|
|
||||||
sdi->channel_groups = g_slist_append(sdi->channel_groups,
|
sdi->channel_groups = g_slist_append(sdi->channel_groups,
|
||||||
devc->digital_groups[i]);
|
devc->digital_groups[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -769,7 +769,6 @@ SR_PRIV int dlm_model_get(char *model_id, char **model_name, int *model_index)
|
||||||
*/
|
*/
|
||||||
SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
|
SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
|
||||||
{
|
{
|
||||||
char tmp[25];
|
|
||||||
int i;
|
int i;
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
@ -799,13 +798,10 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index)
|
||||||
|
|
||||||
/* Add digital channel groups. */
|
/* Add digital channel groups. */
|
||||||
for (i = 0; i < scope_models[model_index].pods; i++) {
|
for (i = 0; i < scope_models[model_index].pods; i++) {
|
||||||
g_snprintf(tmp, sizeof(tmp), "POD%d", i);
|
|
||||||
|
|
||||||
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
|
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
|
||||||
if (!devc->digital_groups[i])
|
if (!devc->digital_groups[i])
|
||||||
return SR_ERR_MALLOC;
|
return SR_ERR_MALLOC;
|
||||||
|
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i);
|
||||||
devc->digital_groups[i]->name = g_strdup(tmp);
|
|
||||||
sdi->channel_groups = g_slist_append(sdi->channel_groups,
|
sdi->channel_groups = g_slist_append(sdi->channel_groups,
|
||||||
devc->digital_groups[i]);
|
devc->digital_groups[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,42 +366,31 @@ SR_API char *sr_samplerate_string(uint64_t samplerate)
|
||||||
SR_API char *sr_period_string(uint64_t v_p, uint64_t v_q)
|
SR_API char *sr_period_string(uint64_t v_p, uint64_t v_q)
|
||||||
{
|
{
|
||||||
double freq, v;
|
double freq, v;
|
||||||
char *o;
|
int prec;
|
||||||
int prec, r;
|
|
||||||
|
|
||||||
freq = 1 / ((double)v_p / v_q);
|
freq = 1 / ((double)v_p / v_q);
|
||||||
|
|
||||||
o = g_malloc0(30 + 1);
|
|
||||||
|
|
||||||
if (freq > SR_GHZ(1)) {
|
if (freq > SR_GHZ(1)) {
|
||||||
v = (double)v_p / v_q * 1000000000000.0;
|
v = (double)v_p / v_q * 1000000000000.0;
|
||||||
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
||||||
r = snprintf(o, 30, "%.*f ps", prec, v);
|
return g_strdup_printf("%.*f ps", prec, v);
|
||||||
} else if (freq > SR_MHZ(1)) {
|
} else if (freq > SR_MHZ(1)) {
|
||||||
v = (double)v_p / v_q * 1000000000.0;
|
v = (double)v_p / v_q * 1000000000.0;
|
||||||
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
||||||
r = snprintf(o, 30, "%.*f ns", prec, v);
|
return g_strdup_printf("%.*f ns", prec, v);
|
||||||
} else if (freq > SR_KHZ(1)) {
|
} else if (freq > SR_KHZ(1)) {
|
||||||
v = (double)v_p / v_q * 1000000.0;
|
v = (double)v_p / v_q * 1000000.0;
|
||||||
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
||||||
r = snprintf(o, 30, "%.*f us", prec, v);
|
return g_strdup_printf("%.*f us", prec, v);
|
||||||
} else if (freq > 1) {
|
} else if (freq > 1) {
|
||||||
v = (double)v_p / v_q * 1000.0;
|
v = (double)v_p / v_q * 1000.0;
|
||||||
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
||||||
r = snprintf(o, 30, "%.*f ms", prec, v);
|
return g_strdup_printf("%.*f ms", prec, v);
|
||||||
} else {
|
} else {
|
||||||
v = (double)v_p / v_q;
|
v = (double)v_p / v_q;
|
||||||
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
prec = ((v - (uint64_t)v) < FLT_MIN) ? 0 : 3;
|
||||||
r = snprintf(o, 30, "%.*f s", prec, v);
|
return g_strdup_printf("%.*f s", prec, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < 0) {
|
|
||||||
/* Something went wrong... */
|
|
||||||
g_free(o);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -422,25 +411,12 @@ SR_API char *sr_period_string(uint64_t v_p, uint64_t v_q)
|
||||||
*/
|
*/
|
||||||
SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q)
|
SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q)
|
||||||
{
|
{
|
||||||
int r;
|
|
||||||
char *o;
|
|
||||||
|
|
||||||
o = g_malloc0(30 + 1);
|
|
||||||
|
|
||||||
if (v_q == 1000)
|
if (v_q == 1000)
|
||||||
r = snprintf(o, 30, "%" PRIu64 "mV", v_p);
|
return g_strdup_printf("%" PRIu64 "mV", v_p);
|
||||||
else if (v_q == 1)
|
else if (v_q == 1)
|
||||||
r = snprintf(o, 30, "%" PRIu64 "V", v_p);
|
return g_strdup_printf("%" PRIu64 "V", v_p);
|
||||||
else
|
else
|
||||||
r = snprintf(o, 30, "%gV", (float)v_p / (float)v_q);
|
return g_strdup_printf("%gV", (float)v_p / (float)v_q);
|
||||||
|
|
||||||
if (r < 0) {
|
|
||||||
/* Something went wrong... */
|
|
||||||
g_free(o);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue