diff options
| author | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
|---|---|---|
| committer | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
| commit | aa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 (patch) | |
| tree | 62f97b4c5acfdb98003568466f878fbd3d6b9dfb /src/add_repo.c | |
| parent | 83d471f2c1d1b1fa6be51f41e4f1c36ab19d7094 (diff) | |
c rewrite
Diffstat (limited to 'src/add_repo.c')
| -rw-r--r-- | src/add_repo.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/add_repo.c b/src/add_repo.c new file mode 100644 index 0000000..049347c --- /dev/null +++ b/src/add_repo.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> + +#include "add_repo.h" +#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); + } + + printf("%s%sAdded %s%s\n", print_pkgit, green, repo_name, color_reset); +}
\ No newline at end of file |
