commit 1cfc01ff3b8b1dd26f98fa268fba021b1f9370a4
parent f88cad538db924b7f3a1d0db26c83b80c15efd6d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 1 Dec 2020 09:53:17 +0100
Rewrite the rng_kiss_read function
Directly use the fscanf function rather than temporally reading the data
in a local buffer.
Diffstat:
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/src/ssp_rng.c b/src/ssp_rng.c
@@ -106,32 +106,17 @@ static res_T
rng_kiss_read(void* data, FILE* file)
{
struct rng_kiss* rng = (struct rng_kiss*)data;
- struct darray_char buf;
- size_t offset = 0;
- size_t bufsz = 64;
+ int n;
res_T res = RES_OK;
- int err;
ASSERT(data && file);
- darray_char_init(&mem_default_allocator, &buf);
- res = darray_char_resize(&buf, bufsz);
- if(res != RES_OK) goto error;
-
- while(fgets(darray_char_data_get(&buf)+offset, (int)(bufsz-offset), file)) {
- /* Ensure that the whole line is read */
- if(strrchr(darray_char_cdata_get(&buf), '\n')) break;
- offset = bufsz-1/*Null char*/;
- bufsz *= 2;
- res = darray_char_resize(&buf, bufsz);
- if(res != RES_OK) goto error;
+ n = fscanf(file, "%u %u %u %u", &rng->x, &rng->y, &rng->z, &rng->c);
+ if(n == EOF || n < 4) {
+ res = RES_IO_ERR;
+ goto error;
}
- err = sscanf(darray_char_cdata_get(&buf), "%u %u %u %u",
- &rng->x, &rng->y, &rng->z, &rng->c);
- res = err == EOF || !err ? RES_IO_ERR : RES_OK;
-
exit:
- darray_char_release(&buf);
return res;
error:
goto exit;