From 72ca5b454d7ff90b2951adc07584f563560db561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Fri, 19 Sep 2003 15:21:43 +0200 Subject: [PATCH] (write_file): New function. (write_string): Simplified error check, it's no real point in calling ferror unless we also call fflush. Rev: src/nettle/examples/io.c:1.5 Rev: src/nettle/examples/io.h:1.3 --- examples/io.c | 10 ++++++++-- examples/io.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/io.c b/examples/io.c index 48d7b801..fdd75e7c 100644 --- a/examples/io.c +++ b/examples/io.c @@ -118,10 +118,16 @@ write_file(const char *name, unsigned size, const char *buffer) res = fwrite(buffer, 1, size, f); - if (res < size || ferror(f)) + if (res < size) res = 0; - fclose(f); + return fclose(f) == 0 && res > 0; +} + +int +write_string(FILE *f, unsigned size, const char *buffer) +{ + size_t res = fwrite(buffer, 1, size, f); return res > 0; } diff --git a/examples/io.h b/examples/io.h index b7530f38..acd864f2 100644 --- a/examples/io.h +++ b/examples/io.h @@ -49,6 +49,9 @@ read_file(const char *name, unsigned size, char **buffer); int write_file(const char *name, unsigned size, const char *buffer); +int +write_string(FILE *f, unsigned size, const char *buffer); + int simple_random(struct yarrow256_ctx *ctx, const char *name); -- GitLab