summaryrefslogtreecommitdiff
path: root/src/sys/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/system.c')
-rw-r--r--src/sys/system.c59
1 files changed, 50 insertions, 9 deletions
diff --git a/src/sys/system.c b/src/sys/system.c
index 63d8297..0d99b28 100644
--- a/src/sys/system.c
+++ b/src/sys/system.c
@@ -16,6 +16,22 @@ typedef struct tiny_sys_test_state
} tiny_sys_test_state_t;
static tiny_sys_test_state_t tiny_sys_test_state;
+static tiny_sys_io_counters_t tiny_sys_io_counters;
+
+void
+tiny_sys_io_counters_reset(void)
+{
+ memset(&tiny_sys_io_counters, 0, sizeof(tiny_sys_io_counters));
+}
+
+void
+tiny_sys_io_counters_get(tiny_sys_io_counters_t *counters)
+{
+ if (counters != NULL)
+ {
+ *counters = tiny_sys_io_counters;
+ }
+}
void
tiny_sys_test_reset(void)
@@ -349,6 +365,11 @@ tiny_sys_file_write(tiny_sys_file_t *file, const void *data, uint32_t length, ui
length = tiny_sys_test_transfer_length(length);
result = WriteFile(native_file(file), data, length, &count, NULL) != 0;
*actual = count;
+ if (result)
+ {
+ tiny_sys_io_counters.write_calls++;
+ tiny_sys_io_counters.write_bytes += count;
+ }
return result;
}
@@ -400,15 +421,19 @@ tiny_sys_file_size(const tiny_sys_file_t *file, uint64_t *size)
bool
tiny_sys_file_truncate(tiny_sys_file_t *file)
{
- return tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_TRUNCATE)
- && SetEndOfFile(native_file(file)) != 0;
+ bool result = tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_TRUNCATE)
+ && SetEndOfFile(native_file(file)) != 0;
+ tiny_sys_io_counters.truncate_calls += result ? 1U : 0U;
+ return result;
}
bool
tiny_sys_file_flush(tiny_sys_file_t *file)
{
- return tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_FLUSH)
- && FlushFileBuffers(native_file(file)) != 0;
+ bool result = tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_FLUSH)
+ && FlushFileBuffers(native_file(file)) != 0;
+ tiny_sys_io_counters.flush_calls += result ? 1U : 0U;
+ return result;
}
bool
@@ -427,6 +452,7 @@ tiny_sys_path_replace(const char *source, const char *destination)
}
free(wide_source);
free(wide_destination);
+ tiny_sys_io_counters.replace_calls += result ? 1U : 0U;
return result;
}
@@ -703,6 +729,11 @@ tiny_sys_file_read(tiny_sys_file_t *file, void *data, uint32_t length, uint32_t
}
while (count < 0 && errno == EINTR);
*actual = count > 0 ? (uint32_t)count : 0;
+ if (count >= 0)
+ {
+ tiny_sys_io_counters.write_calls++;
+ tiny_sys_io_counters.write_bytes += *actual;
+ }
return count >= 0;
}
@@ -769,21 +800,31 @@ tiny_sys_file_truncate(tiny_sys_file_t *file)
return false;
}
position = lseek(native_file(file), 0, SEEK_CUR);
- return position >= 0 && ftruncate(native_file(file), position) == 0;
+ if (position >= 0 && ftruncate(native_file(file), position) == 0)
+ {
+ tiny_sys_io_counters.truncate_calls++;
+ return true;
+ }
+ return false;
}
bool
tiny_sys_file_flush(tiny_sys_file_t *file)
{
- return tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_FLUSH)
- && fsync(native_file(file)) == 0;
+ bool result = tiny_sys_file_valid(file) && !tiny_sys_test_should_fail(TINY_SYS_TEST_FLUSH)
+ && fsync(native_file(file)) == 0;
+ tiny_sys_io_counters.flush_calls += result ? 1U : 0U;
+ return result;
}
bool
tiny_sys_path_replace(const char *source, const char *destination)
{
- return source != NULL && destination != NULL && !tiny_sys_test_should_fail(TINY_SYS_TEST_REPLACE)
- && rename(source, destination) == 0;
+ bool result = source != NULL && destination != NULL
+ && !tiny_sys_test_should_fail(TINY_SYS_TEST_REPLACE)
+ && rename(source, destination) == 0;
+ tiny_sys_io_counters.replace_calls += result ? 1U : 0U;
+ return result;
}
bool