diff options
author | Erich Eckner <git@eckner.net> | 2018-10-23 09:33:30 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-10-23 09:33:30 +0200 |
commit | d646809abf052fd949ca839395735a91d7084198 (patch) | |
tree | 23a0c275b85f760f4cb58f2757bcd1f885a5276a /input_gadgets.c | |
parent | f2aec4e6d375f50616622b0eb75c66fb5b0dc643 (diff) | |
download | anzeige-d646809abf052fd949ca839395735a91d7084198.tar.xz |
put temperature on screen
Diffstat (limited to 'input_gadgets.c')
-rw-r--r-- | input_gadgets.c | 18 |
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; } |