summaryrefslogtreecommitdiff
path: root/input_gadgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'input_gadgets.c')
-rw-r--r--input_gadgets.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/input_gadgets.c b/input_gadgets.c
index 7aeb09a..00a2d36 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -28,7 +28,7 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
return realsize;
}
-int gadgets_retrieve_temperature(char **output)
+int gadgets_retrieve_temperature(unsigned char *output, int max_len)
{
CURL *curl_handle;
CURLcode res;
@@ -78,15 +78,13 @@ int gadgets_retrieve_temperature(char **output)
return EXIT_FAILURE;
}
regfree(&re);
- output[0] = malloc((int)(rm[1].rm_eo - rm[1].rm_so + 1));
- if (output[0] == NULL) {
- fprintf(stderr, "malloc failed allocating %d bytes\n", (int)(rm[1].rm_eo - rm[1].rm_so + 1));
- free(chunk.memory);
- return EXIT_FAILURE;
- }
- printf("allocated %d bytes\n", (int)(rm[1].rm_eo - rm[1].rm_so + 1));
- memmove(output[0], chunk.memory + rm[1].rm_so, (int)(rm[1].rm_eo - rm[1].rm_so));
- output[0][(int)(rm[1].rm_eo - rm[1].rm_so)] = '\0';
+ if ((int)(rm[1].rm_eo - rm[1].rm_so) < max_len - 1)
+ max_len = (int)(rm[1].rm_eo - rm[1].rm_so) + 1;
+ memmove(output, chunk.memory + rm[1].rm_so, max_len - 1);
+ output[max_len - 1] = '\0';
+ for (int i=0; i<max_len; i++)
+ if (output[i] == '.')
+ output[i] = ',';
free(chunk.memory);
return 0;
}