From: Niels Möller Date: Fri, 19 Sep 2003 13:21:43 +0000 (+0200) Subject: (write_file): New function. X-Git-Tag: nettle_1.8_release_20040110~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72ca5b454d7ff90b2951adc07584f563560db561;p=thirdparty%2Fnettle.git (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 --- 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);