aboutsummaryrefslogtreecommitdiff
path: root/src/fileutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileutils.c')
-rw-r--r--src/fileutils.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/fileutils.c b/src/fileutils.c
index 4fba0d0..524a603 100644
--- a/src/fileutils.c
+++ b/src/fileutils.c
@@ -25,7 +25,7 @@ int file_get_content(const char *filepath, char **data, long *size) {
FILE *file = fopen(filepath, "rb");
if(!file) {
int err = -errno;
- perror(filepath);
+ /*perror(filepath);*/
return err;
}
@@ -116,11 +116,11 @@ int file_overwrite(const char *filepath, const char *data, size_t size) {
int file_overwrite_in_dir(const char *dir, const char *filename, const char *data, size_t size) {
char filepath[PATH_MAX];
const char *filepath_components[] = { dir, filename };
- path_join(filepath, filepath_components, 2);
+ int filepath_len = path_join(filepath, filepath_components, 2);
char tmp_filepath[PATH_MAX];
strcpy(tmp_filepath, filepath);
- strcat(tmp_filepath, ".tmp");
+ strcpy(tmp_filepath + filepath_len, ".tmp");
int result = file_overwrite(tmp_filepath, data, size);
if(result != 0)
@@ -130,7 +130,7 @@ int file_overwrite_in_dir(const char *dir, const char *filename, const char *dat
return rename(tmp_filepath, filepath);
}
-void path_join(char *output, const char **components, int num_components) {
+int path_join(char *output, const char **components, int num_components) {
int offset = 0;
for(int i = 0; i < num_components; ++i) {
if(i > 0) {
@@ -143,4 +143,5 @@ void path_join(char *output, const char **components, int num_components) {
offset += component_len;
}
output[offset] = '\0';
+ return offset;
}