mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 18:46:00 +01:00
don't use _from_fd variants
This commit is contained in:
parent
f8f48dcc7d
commit
d613fd41ac
1 changed files with 13 additions and 11 deletions
|
@ -1,5 +1,7 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#define _POSIX_SOURCE
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -295,28 +297,26 @@ zathura_db_read_key_file_from_file(const char* path)
|
|||
}
|
||||
|
||||
/* open file */
|
||||
int fd = open(path, O_RDWR);
|
||||
if (fd == -1) {
|
||||
FILE* file = fopen(path, "r");
|
||||
if (file == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GKeyFile* key_file = g_key_file_new();
|
||||
if (key_file == NULL) {
|
||||
close(fd);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read config file */
|
||||
file_lock_set(fd, F_WRLCK);
|
||||
char* content = girara_file_read_from_fd(fd);
|
||||
file_lock_set(fileno(file), F_WRLCK);
|
||||
char* content = girara_file_read2(file);
|
||||
file_lock_set(fileno(file), F_UNLCK);
|
||||
fclose(file);
|
||||
if (content == NULL) {
|
||||
file_lock_set(fd, F_UNLCK);
|
||||
close(fd);
|
||||
g_key_file_free(key_file);
|
||||
return NULL;
|
||||
}
|
||||
file_lock_set(fd, F_UNLCK);
|
||||
|
||||
close(fd);
|
||||
|
||||
/* parse config file */
|
||||
size_t contentlen = strlen(content);
|
||||
|
@ -369,7 +369,9 @@ zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file)
|
|||
}
|
||||
|
||||
file_lock_set(fd, F_WRLCK);
|
||||
write(fd, content, strlen(content));
|
||||
if (write(fd, content, strlen(content)) == 0) {
|
||||
girara_error("Failed to write to %s", file);
|
||||
}
|
||||
file_lock_set(fd, F_UNLCK);
|
||||
|
||||
close(fd);
|
||||
|
|
Loading…
Reference in a new issue