Переглянути джерело

[file.h] Fixing file_save

Vinicius Teshima 1 рік тому
батько
коміт
c97aacb140
1 змінених файлів з 4 додано та 1 видалено
  1. 4 1
      src/file.h

+ 4 - 1
src/file.h

@@ -34,6 +34,7 @@ enum file_err file_save(const char *filepath, const char *str, size_t str_size);
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 
 struct ret_void_p_err
 file_read_all(const char *filepath)
@@ -109,7 +110,9 @@ err: ;
 enum file_err
 file_save(const char *filepath, const char *str, size_t str_size)
 {
-	int32_t fd = open(filepath, O_WRONLY);
+	int32_t fd = open(filepath,
+			  O_WRONLY | O_CREAT | O_TRUNC,
+			  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 	if ( fd < 0 ) {
 		return FILE_ERR_FAIL_OPEN;
 	}