From 2cf68e0e10250ed20fbdba349cb88a16f44a23e2 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Sat, 17 Aug 2024 22:54:00 -0500 Subject: [PATCH] fix windows compilation error --- c/src/include/utils.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/c/src/include/utils.h b/c/src/include/utils.h index d3c75073..deef1077 100644 --- a/c/src/include/utils.h +++ b/c/src/include/utils.h @@ -132,12 +132,14 @@ typedef struct { } Answer; Answer get_answer(uint16_t id) { - char *linepointer; - char *tabpointer; Answer ret = { .id = id, }; char *answers = get_data_file("answers.tsv"); + char *linepointer, *tabpointer; +#ifdef _WIN32 + rsize_t linemax = strlen(answers) + 1, tabmax; +#endif if (!answers) { fprintf(stderr, "Error: Unable to get data from file\n"); @@ -147,13 +149,27 @@ Answer get_answer(uint16_t id) { char s_id[6]; snprintf(s_id, sizeof(s_id), "%" PRIu16, id); +#ifdef _WIN32 + char *line = strtok_s(answers, &linemax, "\n", &linepointer); // skip header + while ((line = strtok_s(NULL, &linemax, "\n", &linepointer)) != NULL) { + tabmax = strlen(line) + 1; +#else char *line = strtok_r(answers, "\n", &linepointer); // skip header while ((line = strtok_r(NULL, "\n", &linepointer)) != NULL) { +#endif +#ifdef _WIN32 + char *token = strtok_s(line, &tabmax, "\t", &tabpointer); +#else char *token = strtok_r(line, "\t", &tabpointer); +#endif if (strcmp(token, s_id) != 0) continue; +#ifdef _WIN32 + token = strtok_s(NULL, &tabmax, "\t", &tabpointer); +#else token = strtok_r(NULL, "\t", &tabpointer); +#endif if (!token) continue; @@ -168,12 +184,20 @@ Answer get_answer(uint16_t id) { return ret; } +#ifdef _WIN32 + token = strtok_s(NULL, &tabmax, "\t", &tabpointer); +#else token = strtok_r(NULL, "\t", &tabpointer); +#endif if (!token) continue; size_t size = strtoull(token, NULL, 10); +#ifdef _WIN32 + token = strtok_s(NULL, &tabmax, "\t", &tabpointer); +#else token = strtok_r(NULL, "\t", &tabpointer); +#endif if (!token) continue;