summaryrefslogtreecommitdiffstats
path: root/fpart
diff options
context:
space:
mode:
Diffstat (limited to 'fpart')
-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