2023-11-08 12:10:27 -05:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define BUTTON "\n### [More](https://urlz.fr/mqBB)"
|
|
|
|
#define TOTAL_SIZE 2272
|
|
|
|
#define MAX_SIZE TOTAL_SIZE - strlen(BUTTON)
|
|
|
|
|
|
|
|
char* read_file(const char* path)
|
|
|
|
{
|
|
|
|
char* content;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
goto open_fail;
|
|
|
|
|
|
|
|
content = malloc((TOTAL_SIZE + 1) * sizeof(char));
|
|
|
|
if (content == NULL)
|
|
|
|
goto alloc_fail;
|
|
|
|
|
|
|
|
int written = read(fd, content, MAX_SIZE);
|
|
|
|
if (written == -1)
|
|
|
|
goto read_fail;
|
|
|
|
|
|
|
|
content[written] = '\0';
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return content;
|
|
|
|
|
|
|
|
read_fail:
|
|
|
|
alloc_fail:
|
|
|
|
free(content);
|
|
|
|
|
|
|
|
open_fail:
|
|
|
|
close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int write_file(const char* path, const char* content)
|
|
|
|
{
|
|
|
|
int fd = open(path, O_WRONLY | O_TRUNC);
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return write(fd, content, strlen(content));
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
|
|
|
char* path;
|
|
|
|
|
|
|
|
if (ac > 2)
|
|
|
|
path = av[1];
|
|
|
|
else
|
|
|
|
path = "README_COMPLET.md";
|
|
|
|
|
|
|
|
char* content = read_file(path);
|
|
|
|
if (content == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2023-11-08 12:19:16 -05:00
|
|
|
if (strlen(content) == MAX_SIZE)
|
|
|
|
strcat(content, BUTTON);
|
2023-11-08 12:10:27 -05:00
|
|
|
|
|
|
|
int ret = write_file("README.md", content);
|
|
|
|
free(content);
|
|
|
|
return ret;
|
|
|
|
}
|