summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2015-12-15 21:35:44 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-12-15 23:06:26 +1100
commitba8eeee29b8039d8f7d9eee5362117c2235296f0 (patch)
tree98fd3c28a9df08151127a11ec70e32bad1d5312d
parent4c6b42489263f83dc687e2b13745f6e815fb417b (diff)
downloadffs-ba8eeee29b8039d8f7d9eee5362117c2235296f0.zip
ffs-ba8eeee29b8039d8f7d9eee5362117c2235296f0.tar.gz
use open/read/write for create_regular_file
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--fpart/src/command.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/fpart/src/command.c b/fpart/src/command.c
index 6b4e56e..81cbc70 100644
--- a/fpart/src/command.c
+++ b/fpart/src/command.c
@@ -172,14 +172,15 @@ int create_regular_file(const char *path, size_t size, char pad)
{
assert(path != NULL);
- RAII(FILE*, file, fopen(path, "w"), fclose);
- if (file == NULL) {
+ int fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+ if (fd == -1) {
ERRNO(errno);
return -1;
}
- if (ftruncate(fileno(file), size) < 0) {
+ if (ftruncate(fd, size) < 0) {
ERRNO(errno);
+ close(fd);
return -1;
}
@@ -188,15 +189,17 @@ int create_regular_file(const char *path, size_t size, char pad)
memset(buf, pad, page_size);
while (0 < size) {
- ssize_t rc = fwrite(buf, 1, min(sizeof(buf), size), file);
- if (rc <= 0 && ferror(file)) {
+ ssize_t rc = write(fd, buf, min(sizeof(buf), size));
+ if (rc <= 0) {
ERRNO(errno);
+ close(fd);
return -1;
}
size -= rc;
}
+ close(fd);
return 0;
}
OpenPOWER on IntegriCloud