Commit ce79d3e1 authored by Niels Möller's avatar Niels Möller

examples/io.c: Made write_file use write_string.

parent a1b48f8e
2012-04-14 Niels Möller <nisse@lysator.liu.se>
* examples/io.c (write_file): Use write_string.
* examples/Makefile.in (base64enc): New target. Also added missing
io.o dependency to several other targets.
......
......@@ -132,28 +132,24 @@ read_file(const char *name, unsigned max_size, char **contents)
}
int
write_file(const char *name, unsigned size, const char *buffer)
write_string(FILE *f, unsigned size, const char *buffer)
{
FILE *f = fopen(name, "wb");
unsigned res;
if (!f)
return 0;
res = fwrite(buffer, 1, size, f);
if (res < size)
res = 0;
size_t res = fwrite(buffer, 1, size, f);
return fclose(f) == 0 && res > 0;
return res == size;
}
int
write_string(FILE *f, unsigned size, const char *buffer)
write_file(const char *name, unsigned size, const char *buffer)
{
size_t res = fwrite(buffer, 1, size, f);
FILE *f = fopen(name, "wb");
int res;
if (!f)
return 0;
return res == size;
res = write_string(f, size, buffer);
return fclose(f) == 0 && res;
}
int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment