diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-06-29 03:19:33 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-06-29 03:19:33 +0000 |
| commit | d85350854dca4c6495cb78c89ff4934c7a908509 (patch) | |
| tree | 2b8cbd9db60f81b0ab538be447d318017e064ff1 /src/add_repo.c | |
| parent | 5f153abb7345aa4ddc574621d6842e07f80a559c (diff) | |
FCC: banned.h
Diffstat (limited to 'src/add_repo.c')
| -rw-r--r-- | src/add_repo.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/add_repo.c b/src/add_repo.c index 52afc80..949c992 100644 --- a/src/add_repo.c +++ b/src/add_repo.c @@ -26,26 +26,32 @@ #include "vars.h" void add_repo(const char *repo, const char *repo_name) { - bool is_previous_repos = false; - char rfile_line[1024]; - char rfile_contents[8192] = {0}; - - if (file_exists(repo_file)) { - FILE *rfile = fopen(repo_file, "r"); - if (rfile) { - while (fgets(rfile_line, sizeof(rfile_line), rfile)) { - strcat(rfile_contents, rfile_line); - } - fclose(rfile); - is_previous_repos = true; - } - } - - char *previous_repos = is_previous_repos ? rfile_contents : ""; - - FILE *wfile = fopen(repo_file, "w"); - if (wfile) { - fprintf(wfile, "%srepositories[\"%s\"] = { url = \"%s\" }\n", previous_repos, repo_name, repo); - fclose(wfile); - } -}
\ No newline at end of file + bool is_previous_repos = false; + char rfile_line[1024]; + char rfile_contents[8192] = {0}; + + if (file_exists(repo_file)) { + FILE *rfile = fopen(repo_file, "r"); + if (rfile) { + while (fgets(rfile_line, sizeof(rfile_line), rfile)) { + size_t current_len = strlen(rfile_contents); + size_t remaining = sizeof(rfile_contents) - current_len; + if (remaining > 1) { + snprintf(rfile_contents + current_len, remaining, "%s", rfile_line); + } else { + break; + } + } + fclose(rfile); + is_previous_repos = true; + } + } + + char *previous_repos = is_previous_repos ? rfile_contents : ""; + + FILE *wfile = fopen(repo_file, "w"); + if (wfile) { + fprintf(wfile, "%srepositories[\"%s\"] = { url = \"%s\" }\n", previous_repos, repo_name, repo); + fclose(wfile); + } +} |
