Skip to content
Snippets Groups Projects
Commit ce79d3e1 authored by Niels Möller's avatar Niels Möller
Browse files

examples/io.c: Made write_file use write_string.

parent a1b48f8e
No related branches found
No related tags found
No related merge requests found
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;
return res == size;
if (!f)
return 0;
res = write_string(f, size, buffer);
return fclose(f) == 0 && res;
}
int
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment