summaryrefslogtreecommitdiff
path: root/src/util/file
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-06-24 14:34:21 -0400
committerAndrew Opalach <andrew@akon.city> 2024-06-24 14:34:21 -0400
commita320ee672ccf52297dc509b25ed263f165709b31 (patch)
treeef78116173aa19c28ee4a46f861861f700528c50 /src/util/file
parent3d1ab87859a291cf8965b56703931193d5e6ae25 (diff)
downloadlibnaunet-a320ee672ccf52297dc509b25ed263f165709b31.tar.gz
libnaunet-a320ee672ccf52297dc509b25ed263f165709b31.tar.bz2
libnaunet-a320ee672ccf52297dc509b25ed263f165709b31.zip
Add multiplex, a bunch of cleanup
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util/file')
-rw-r--r--src/util/file/file_linux.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/util/file/file_linux.c b/src/util/file/file_linux.c
index 403d685..ac78bd8 100644
--- a/src/util/file/file_linux.c
+++ b/src/util/file/file_linux.c
@@ -5,14 +5,9 @@
#include "file.h"
-static bool lock_file_internal(s32 fd)
+static bool lock_file_internal(s32 fd, size_t size)
{
- struct flock l = {
- .l_type = F_WRLCK,
- .l_whence = SEEK_SET,
- .l_start = 0,
- .l_len = 0
- };
+ struct flock l = { .l_type = F_WRLCK, .l_whence = SEEK_SET, .l_start = 0, .l_len = size };
if (fcntl(fd, F_SETLKW, &l) == -1) {
al_log_error("file", "fcntl(F_SETLKW) failed (%s).", aki_strerror(errno));
close(fd);
@@ -27,7 +22,7 @@ bool aki_file_open(struct aki_file *file, str *path, s32 flags)
char *c_str = al_str_to_c_str(path);
s32 oflags = (flags & AKI_FILE_READONLY) ? O_RDONLY : O_RDWR;
if (flags & AKI_FILE_CREATE) oflags |= O_CREAT;
- file->fd = open(c_str, oflags, 0666);
+ file->fd = open(c_str, oflags, 0644);
al_free(c_str);
if (file->fd == -1) {
al_log_error("file", "open(%.*s) failed (%s).", AL_STR_PRINTF(path), aki_strerror(errno));
@@ -41,7 +36,7 @@ bool aki_file_open(struct aki_file *file, str *path, s32 flags)
return false;
}
file->filesize = sb.st_size;
- if (flags & AKI_FILE_LOCK) lock_file_internal(file->fd);
+ if (flags & AKI_FILE_LOCK) lock_file_internal(file->fd, file->filesize);
return true;
}