summaryrefslogtreecommitdiff
path: root/src/util/file
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/file
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/file')
-rw-r--r--src/util/file/file_linux.c19
-rw-r--r--src/util/file/util.c6
2 files changed, 16 insertions, 9 deletions
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;