summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-12-26 15:24:35 -0500
committerAndrew Opalach <andrew@akon.city> 2024-12-26 15:24:35 -0500
commitbe4eb3831a2e5b44fb6e4c2d077e3c07edf6b776 (patch)
treedc0f0479070cc716fba9e26d4848a9786913c823 /src/util
parentf5df41d650ea03de846466c66a62d0517b22f375 (diff)
downloadlibnaunet-be4eb3831a2e5b44fb6e4c2d077e3c07edf6b776.tar.gz
libnaunet-be4eb3831a2e5b44fb6e4c2d077e3c07edf6b776.tar.bz2
libnaunet-be4eb3831a2e5b44fb6e4c2d077e3c07edf6b776.zip
Revise style and cleanup
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/buffer.c3
-rw-r--r--src/util/file/file_linux.c19
-rw-r--r--src/util/file/util.c6
-rw-r--r--src/util/thread/thread_linux.c3
-rw-r--r--src/util/thread/thread_windows.c3
-rw-r--r--src/util/timer/timer_windows.c3
6 files changed, 24 insertions, 13 deletions
diff --git a/src/util/buffer.c b/src/util/buffer.c
index 1d343e3..0bd36b4 100644
--- a/src/util/buffer.c
+++ b/src/util/buffer.c
@@ -35,8 +35,9 @@ void nn_buffer_write(struct nn_buffer *buf, void *data, size_t index, size_t siz
{
size_t reach = index + size;
nn_buffer_ensure_space(buf, reach);
- if (reach > buf->size)
+ if (reach > buf->size) {
buf->size = reach;
+ }
al_memcpy(&buf->data[index], data, size);
}
diff --git a/src/util/file/file_linux.c b/src/util/file/file_linux.c
index 9c6b1ce..a362637 100644
--- a/src/util/file/file_linux.c
+++ b/src/util/file/file_linux.c
@@ -30,8 +30,9 @@ bool nn_file_open(struct nn_file *file, str *path, s32 flags)
{
al_assert(!((flags & NNWT_FILE_READONLY) && (flags & NNWT_FILE_LOCK)));
s32 oflags = flags & NNWT_FILE_READONLY ? O_RDONLY : O_RDWR;
- if (flags & NNWT_FILE_CREATE)
+ if (flags & NNWT_FILE_CREATE) {
oflags |= O_CREAT;
+ }
char *c_str = al_str_to_c_str(path);
file->fd = open(c_str, oflags, 0644);
@@ -80,8 +81,9 @@ bool nn_file_create(str *path)
off_t nn_file_seek(struct nn_file *file, off_t offset, s32 whence)
{
off_t res = lseek(file->fd, offset, whence);
- if (res == (off_t)-1)
+ if (res == (off_t)-1) {
al_log_error("file", "lseek(%jd, %d) failed (%s).", (intmax_t)offset, whence, nn_strerror(errno));
+ }
return res;
}
@@ -148,13 +150,16 @@ void *nn_file_mremap(struct nn_file *file, size_t size, void *old_map)
void nn_file_munmap(struct nn_file *file, void *map)
{
s32 ret = munmap(map, file->filesize);
- if (ret != 0)
+ if (ret != 0) {
al_log_error("file", "munmap(%p, %zu) failed (%s).", map, file->filesize, nn_strerror(errno));
+ }
}
void nn_file_close(struct nn_file *file)
{
- if (file->locked) unlock_file_internal(file->fd, file->filesize);
+ if (file->locked) {
+ unlock_file_internal(file->fd, file->filesize);
+ }
close(file->fd);
}
@@ -184,8 +189,9 @@ bool nn_dir_exists(str *path)
dir.dir = opendir(c_str);
al_free(c_str);
if (!dir.dir) {
- if (errno != ENOENT)
+ if (errno != ENOENT) {
al_log_error("file", "opendir(%.*s) failed (%s).", AL_STR_PRINTF(path), nn_strerror(errno));
+ }
return false;
}
closedir(dir.dir);
@@ -207,8 +213,9 @@ bool nn_dir_create(str *path)
bool nn_dir_read(struct nn_dir *dir, struct nn_dir_entry *entry)
{
if (!(entry->entry = readdir(dir->dir))) {
- if (errno)
+ if (errno) {
al_log_error("file", "readdir() failed (%s).", nn_strerror(errno));
+ }
return false;
}
diff --git a/src/util/file/util.c b/src/util/file/util.c
index 50e2c4a..eab9893 100644
--- a/src/util/file/util.c
+++ b/src/util/file/util.c
@@ -26,9 +26,9 @@ s32 nn_file_read_as_c_str(struct nn_file *file, char **out)
s32 nn_file_replace(struct nn_file *file, str *buf)
{
- if (nn_file_seek(file, 0, SEEK_SET) == (off_t)-1 ||
- !nn_file_write(file, buf->data, buf->len) ||
- !nn_file_truncate(file, buf->len)) {
+ if ((nn_file_seek(file, 0, SEEK_SET) == (off_t)-1) ||
+ (!nn_file_write(file, buf->data, buf->len)) ||
+ (!nn_file_truncate(file, buf->len))) {
return -1;
}
return buf->len;
diff --git a/src/util/thread/thread_linux.c b/src/util/thread/thread_linux.c
index bb5bcbc..5fc1081 100644
--- a/src/util/thread/thread_linux.c
+++ b/src/util/thread/thread_linux.c
@@ -70,8 +70,9 @@ void nn_cond_init(struct nn_cond *cond)
void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex)
{
cond->condition = false;
- while (!cond->condition)
+ while (!cond->condition) {
pthread_cond_wait(&cond->cond, &mutex->mutex);
+ }
}
bool nn_cond_is_waiting(struct nn_cond *cond)
diff --git a/src/util/thread/thread_windows.c b/src/util/thread/thread_windows.c
index ded3b6c..4104bb3 100644
--- a/src/util/thread/thread_windows.c
+++ b/src/util/thread/thread_windows.c
@@ -65,8 +65,9 @@ void nn_cond_init(struct nn_cond *cond)
void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex)
{
cond->condition = false;
- while (!cond->condition)
+ while (!cond->condition) {
SleepConditionVariableCS(&cond->cond, &mutex->mutex, INFINITE);
+ }
}
bool nn_cond_is_waiting(struct nn_cond *cond)
diff --git a/src/util/timer/timer_windows.c b/src/util/timer/timer_windows.c
index 198cb32..f26e56a 100644
--- a/src/util/timer/timer_windows.c
+++ b/src/util/timer/timer_windows.c
@@ -16,5 +16,6 @@ u64 nn_get_timestamp(void)
{
FILETIME ft;
GetSystemTimePreciseAsFileTime(&ft);
- return (((LARGE_INTEGER){ .LowPart = ft.dwLowDateTime, .HighPart = ft.dwHighDateTime }).QuadPart - UNIX_TIME_START) / 10Lu;
+ return (((LARGE_INTEGER){ .LowPart = ft.dwLowDateTime, .HighPart = ft.dwHighDateTime }).QuadPart -
+ UNIX_TIME_START) / 10Lu;
}