소스 검색

[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;
 	}