feat: use paste size instead of NULL byte in order to write the paste

Previously, the pastes were written to disk until feuille encountered
a NULL byte. This is now fixed.

+ version bump.
This commit is contained in:
Tom MTT 2022-11-29 13:57:11 +01:00
parent b61f5c4cae
commit 8c30d271df
7 changed files with 23 additions and 20 deletions

4
bin.c
View file

@ -83,7 +83,7 @@ int paste_exists(char *id)
* id: the ID of the paste.
* -> 0 if done, -1 if not.
*/
int write_paste(char *paste, char *id)
int write_paste(char *paste, unsigned long paste_size, char *id)
{
/* open the file with write access */
FILE *file;
@ -91,7 +91,7 @@ int write_paste(char *paste, char *id)
return -1;
/* write the content to file */
if (fputs(paste, file) == -1) {
if (fwrite(paste, paste_size, sizeof(char), file) == -1) {
fclose(file);
return -1;
}