aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-12 19:11:35 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 13:38:25 +0200
commit1f506a17903f5eeaded9065e42726c1a09dc6f89 (patch)
tree6f3cff994ca5794ef41777845ebc7ff6d41525cb /lib/io/src
parenteb9a4b9034453ae3093d678a6f3898303dc5a5a0 (diff)
libio: flip the meaning of the ostream_t sparse flag
Instead of "open sparse", make that the default and turn it into a "no sparse" flag. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src')
-rw-r--r--lib/io/src/unix/ostream.c21
-rw-r--r--lib/io/src/win32/ostream.c24
2 files changed, 23 insertions, 22 deletions
diff --git a/lib/io/src/unix/ostream.c b/lib/io/src/unix/ostream.c
index 702a354..bc69f32 100644
--- a/lib/io/src/unix/ostream.c
+++ b/lib/io/src/unix/ostream.c
@@ -49,15 +49,7 @@ static int realize_sparse(file_ostream_t *file)
if (file->sparse_count == 0)
return 0;
- if (file->flags & OSTREAM_OPEN_SPARSE) {
- if (lseek(file->fd, file->sparse_count, SEEK_CUR) == (off_t)-1)
- goto fail;
-
- if (ftruncate(file->fd, file->size) != 0)
- goto fail;
-
- file->sparse_count = 0;
- } else {
+ if (file->flags & OSTREAM_OPEN_NO_SPARSE) {
bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count;
buffer = calloc(1, bufsz);
if (buffer == NULL)
@@ -76,6 +68,14 @@ static int realize_sparse(file_ostream_t *file)
}
free(buffer);
+ } else {
+ if (lseek(file->fd, file->sparse_count, SEEK_CUR) == (off_t)-1)
+ goto fail;
+
+ if (ftruncate(file->fd, file->size) != 0)
+ goto fail;
+
+ file->sparse_count = 0;
}
return 0;
@@ -194,5 +194,6 @@ ostream_t *ostream_open_file(const char *path, int flags)
ostream_t *ostream_open_stdout(void)
{
- return ostream_open_handle("stdout", STDOUT_FILENO, 0);
+ return ostream_open_handle("stdout", STDOUT_FILENO,
+ OSTREAM_OPEN_NO_SPARSE);
}
diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c
index 9b488d8..edbefc7 100644
--- a/lib/io/src/win32/ostream.c
+++ b/lib/io/src/win32/ostream.c
@@ -43,17 +43,7 @@ static int realize_sparse(file_ostream_t *file)
if (file->sparse_count == 0)
return 0;
- if (file->flags & OSTREAM_OPEN_SPARSE) {
- pos.QuadPart = file->sparse_count;
-
- if (!SetFilePointerEx(file->hnd, pos, NULL, FILE_CURRENT))
- goto fail;
-
- if (!SetEndOfFile(file->hnd))
- goto fail;
-
- file->sparse_count = 0;
- } else {
+ if (file->flags & OSTREAM_OPEN_NO_SPARSE) {
bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count;
buffer = calloc(1, bufsz);
@@ -75,6 +65,16 @@ static int realize_sparse(file_ostream_t *file)
}
free(buffer);
+ } else {
+ pos.QuadPart = file->sparse_count;
+
+ if (!SetFilePointerEx(file->hnd, pos, NULL, FILE_CURRENT))
+ goto fail;
+
+ if (!SetEndOfFile(file->hnd))
+ goto fail;
+
+ file->sparse_count = 0;
}
return 0;
@@ -213,5 +213,5 @@ ostream_t *ostream_open_stdout(void)
{
HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE);
- return ostream_open_handle("stdout", hnd, 0);
+ return ostream_open_handle("stdout", hnd, OSTREAM_OPEN_NO_SPARSE);
}