mirror of
				https://github.com/theoludwig/libcproject.git
				synced 2025-05-21 23:21:15 +02:00 
			
		
		
		
	fix: handle filesystem read and write errors
This commit is contained in:
		| @@ -8,7 +8,9 @@ int filesystem_read(char *path, char **file_content, off_t *file_size) { | ||||
|   (*file_size) = lseek(file_descriptor, 0, SEEK_END); | ||||
|   lseek(file_descriptor, 0, SEEK_SET); | ||||
|   (*file_content) = malloc(*file_size); | ||||
|   read(file_descriptor, *file_content, *file_size); | ||||
|   if (read(file_descriptor, *file_content, *file_size) == -1) { | ||||
|     return -1; | ||||
|   } | ||||
|   close(file_descriptor); | ||||
|   return 0; | ||||
| } | ||||
| @@ -18,7 +20,9 @@ int filesystem_write(char *path, char *file_content, off_t file_size) { | ||||
|   if (file_descriptor == -1) { | ||||
|     return -1; | ||||
|   } | ||||
|   write(file_descriptor, file_content, file_size); | ||||
|   if (write(file_descriptor, file_content, file_size) == -1) { | ||||
|     return -1; | ||||
|   } | ||||
|   close(file_descriptor); | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -19,8 +19,8 @@ | ||||
|  * @param file_content | ||||
|  * @param file_size | ||||
|  * @return int | ||||
|  * @retval -1 if the file does not exist | ||||
|  * @retval 0 for success | ||||
|  * @retval -1 if the file does not exist or if there is an error. | ||||
|  * @retval 0 for success. | ||||
|  * @since v1.0.0 | ||||
|  */ | ||||
| int filesystem_read(char *path, char **file_content, off_t *file_size); | ||||
| @@ -32,8 +32,8 @@ int filesystem_read(char *path, char **file_content, off_t *file_size); | ||||
|  * @param file_content | ||||
|  * @param file_size | ||||
|  * @return int | ||||
|  * @retval -1 if errors | ||||
|  * @retval 0 for success | ||||
|  * @retval -1 if there is an error. | ||||
|  * @retval 0 for success. | ||||
|  * @since v1.0.0 | ||||
|  */ | ||||
| int filesystem_write(char *path, char *file_content, off_t file_size); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user