aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declare.c2
-rw-r--r--src/files.c223
-rw-r--r--src/help.c2
-rw-r--r--src/is_updated.c2
-rw-r--r--src/list_pkgs.c2
-rw-r--r--src/lua_state.c20
-rw-r--r--src/set_install_directories.c2
-rw-r--r--src/setup_dirs.c2
-rw-r--r--src/setup_pkgit.c2
-rw-r--r--src/update_all.c2
-rw-r--r--src/vars.c66
11 files changed, 164 insertions, 161 deletions
diff --git a/src/declare.c b/src/declare.c
index 07bf68d..4974c22 100644
--- a/src/declare.c
+++ b/src/declare.c
@@ -27,7 +27,7 @@
#include "update_pkg.h"
#include "lua_state.h"
-void declare() {
+void declare(void) {
init_lua_state();
cache_repos();
for (size_t i = 0; i < cached_repos_count; i++) {
diff --git a/src/files.c b/src/files.c
index 0cd301d..9f13759 100644
--- a/src/files.c
+++ b/src/files.c
@@ -28,133 +28,136 @@
#include <unistd.h>
const char *get_filename_ext(const char *filename) {
- const char *dot = strrchr(filename, '.');
- if (!dot || dot == filename) return "";
- return dot + 1;
+ const char *dot = strrchr(filename, '.');
+ if (!dot || dot == filename) return "";
+ return dot + 1;
}
static int write_all(int fd, const void *buf, size_t size) {
- while (size) {
- ssize_t written = write(fd, buf, size);
- if (written < 0) {
- return -1;
- }
+ while (size) {
+ ssize_t written = write(fd, buf, size);
+ if (written < 0) {
+ return -1;
+ }
- size -= written;
- buf = (const char *)buf + written;
- }
+ size -= written;
+ buf = (const char *)buf + written;
+ }
- return 0;
+ return 0;
}
static int copy_file_content(int src_fd, int dst_fd) {
- char buf[4096];
- ssize_t readed;
- while ((readed = read(src_fd, buf, sizeof(buf))) > 0) {
- if (write_all(dst_fd, buf, readed) < 0) {
- perror("write_all");
- return -1;
- }
- }
-
- if (readed < 0) {
- perror("read");
- return -1;
- }
-
- return 0;
+ char buf[4096];
+ ssize_t readed;
+ while ((readed = read(src_fd, buf, sizeof(buf))) > 0) {
+ if (write_all(dst_fd, buf, readed) < 0) {
+ perror("write_all");
+ return -1;
+ }
+ }
+
+ if (readed < 0) {
+ perror("read");
+ return -1;
+ }
+
+ return 0;
}
static int copy_at(int src_dir_fd, const char *src_path, int dst_dir_fd, const char *dst_path);
static int copy_dir_content(int src_fd, int dst_fd) {
- int ret = -1;
- // duplicate the descriptor to prevent closedir from closing original one
- src_fd = dup(src_fd);
- if (src_fd < 0) {
- perror("dup");
- goto cleanup0;
- }
-
- DIR *src_dir = fdopendir(src_fd);
- if (!src_dir) {
- perror("fdopendir");
- close(src_fd);
- goto cleanup0;
- }
-
- for (struct dirent *ent; (errno = 0, ent = readdir(src_dir));) {
- if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
- continue;
- }
-
- if (copy_at(src_fd, ent->d_name, dst_fd, ent->d_name) < 0) {
- goto cleanup1;
- }
- }
-
- if (errno != 0) {
- perror("readdir");
- goto cleanup1;
- }
-
- ret = 0;
-
-cleanup1:
- closedir(src_dir);
-cleanup0:
- return ret;
+ int ret = -1;
+ // duplicate the descriptor to prevent closedir from closing original one
+ src_fd = dup(src_fd);
+ if (src_fd < 0) {
+ perror("dup");
+ goto cleanup0;
+ }
+
+ DIR *src_dir = fdopendir(src_fd);
+ if (!src_dir) {
+ perror("fdopendir");
+ close(src_fd);
+ goto cleanup0;
+ }
+
+ for (struct dirent *ent; (errno = 0, ent = readdir(src_dir));) {
+ if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
+ continue;
+ }
+
+ if (copy_at(src_fd, ent->d_name, dst_fd, ent->d_name) < 0) {
+ goto cleanup1;
+ }
+ }
+
+ if (errno != 0) {
+ perror("readdir");
+ goto cleanup1;
+ }
+
+ ret = 0;
+
+ cleanup1:
+ closedir(src_dir);
+ cleanup0:
+ return ret;
}
static int copy_at(int src_dir_fd, const char *src_path, int dst_dir_fd, const char *dst_path) {
- int ret = -1;
- int src_fd = openat(src_dir_fd, src_path, O_NOFOLLOW | O_RDONLY);
- if (src_fd < 0) {
- perror("openat");
- goto cleanup0;
- }
-
- struct stat stat;
- if (fstat(src_fd, &stat) < 0) {
- perror("fstat");
- goto cleanup1;
- }
-
- int dst_oflag = O_NOFOLLOW;
- if (S_ISDIR(stat.st_mode)) {
- if (mkdirat(dst_dir_fd, dst_path, stat.st_mode) < 0) {
- perror("mkdirat");
- goto cleanup1;
- }
-
- dst_oflag |= O_RDONLY | O_DIRECTORY;
- } else {
- dst_oflag |= O_WRONLY | O_CREAT | O_EXCL;
- }
-
- int dst_fd = openat(dst_dir_fd, dst_path, dst_oflag, stat.st_mode);
- if (dst_fd < 0) {
- perror("openat");
- goto cleanup1;
- }
-
- switch (stat.st_mode & S_IFMT) {
- case S_IFDIR:
- ret = copy_dir_content(src_fd, dst_fd);
- break;
- case S_IFREG:
- ret = copy_file_content(src_fd, dst_fd);
- break;
- default:
- fprintf(stderr, "copy_at: unsupported file inode type\n");
- }
-
-cleanup1:
- close(src_fd);
-cleanup0:
- return ret;
+ int ret = -1;
+ int src_fd = openat(src_dir_fd, src_path, O_NOFOLLOW | O_RDONLY);
+ if (src_fd < 0) {
+ perror("openat");
+ goto cleanup0;
+ }
+
+ struct stat stat;
+ if (fstat(src_fd, &stat) < 0) {
+ perror("fstat");
+ goto cleanup1;
+ }
+
+ int dst_oflag = O_NOFOLLOW;
+ if (S_ISDIR(stat.st_mode)) {
+ if (mkdirat(dst_dir_fd, dst_path, stat.st_mode) < 0) {
+ perror("mkdirat");
+ goto cleanup1;
+ }
+
+ dst_oflag |= O_RDONLY | O_DIRECTORY;
+ } else {
+ dst_oflag |= O_WRONLY | O_CREAT | O_EXCL;
+ }
+
+ int dst_fd = openat(dst_dir_fd, dst_path, dst_oflag, stat.st_mode);
+ if (dst_fd < 0) {
+ perror("openat");
+ goto cleanup1;
+ }
+
+ switch (stat.st_mode & S_IFMT) {
+ case S_IFDIR:
+ ret = copy_dir_content(src_fd, dst_fd);
+ break;
+ case S_IFREG:
+ ret = copy_file_content(src_fd, dst_fd);
+ break;
+ default:
+ fprintf(stderr, "copy_at: unsupported file inode type\n");
+ }
+ goto cleanup2;
+
+ cleanup2:
+ close(dst_fd);
+ cleanup1:
+ close(src_fd);
+ cleanup0:
+ return ret;
}
void cpdir(const char *src_path, const char *dst_path) {
- copy_at(AT_FDCWD, src_path, AT_FDCWD, dst_path);
+ copy_at(AT_FDCWD, src_path, AT_FDCWD, dst_path);
}
diff --git a/src/help.c b/src/help.c
index d7e01a0..6c6ef94 100644
--- a/src/help.c
+++ b/src/help.c
@@ -23,7 +23,7 @@
#include "help.h"
#include "vars.h"
-void help() {
+void help(void) {
if (is_verbose) {
printf("%s , \n", bold_magenta);
printf("%s / \\ \n", bold_magenta);
diff --git a/src/is_updated.c b/src/is_updated.c
index 3e1dd43..16e860b 100644
--- a/src/is_updated.c
+++ b/src/is_updated.c
@@ -42,7 +42,7 @@ bool is_updated(const char *src) {
return result;
}
-bool is_bldit_usable() {
+bool is_bldit_usable(void) {
char* bldit_version = bldit_getver();
if (!bldit_version) return false;
if (strcmp(bldit_version, version) == 0) return true;
diff --git a/src/list_pkgs.c b/src/list_pkgs.c
index ccc0e8a..365e9b8 100644
--- a/src/list_pkgs.c
+++ b/src/list_pkgs.c
@@ -26,7 +26,7 @@
#include "lua_state.h"
#include "vars.h"
-void list_pkgs() {
+void list_pkgs(void) {
char* src_code = map_get(&cached_install_directories, "src");
struct dirent* dirent_ptr;
DIR* dir_ptr = opendir(src_code);
diff --git a/src/lua_state.c b/src/lua_state.c
index 39dd089..2768ba7 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -47,7 +47,7 @@ void push_lua_path(lua_State *L, const char *new_path) {
lua_pop(L, 1);
}
-void init_lua_state() {
+void init_lua_state(void) {
if (L != NULL) return;
L = luaL_newstate();
luaL_openlibs(L);
@@ -80,7 +80,7 @@ void init_lua_state() {
config_loaded = true;
}
-void init_bldit() {
+void init_bldit(void) {
if (B != NULL) return;
B = luaL_newstate();
luaL_openlibs(B);
@@ -94,7 +94,7 @@ void init_bldit() {
bldit_loaded = true;
}
-void free_lua_state() {
+void free_lua_state(void) {
if (L != NULL) {
lua_close(L);
L = NULL;
@@ -102,9 +102,9 @@ void free_lua_state() {
config_loaded = false;
}
-lua_State *get_lua_state() { return L; }
+lua_State *get_lua_state(void) { return L; }
-void cache_prefix_directory() {
+void cache_prefix_directory(void) {
lua_getglobal(L, "prefix");
if (!lua_isstring(L, -1)) {
printf(
@@ -117,7 +117,7 @@ void cache_prefix_directory() {
lua_pop(L, 1);
}
-void cache_install_directories() {
+void cache_install_directories(void) {
if (!config_loaded || !lua_istable(L, -1)) {
lua_getglobal(L, "install_directories");
}
@@ -440,7 +440,7 @@ bool repo_uninstall(const char *repository, const char *target) {
return target_loop_success;
}
-char* bldit_getver() {
+char* bldit_getver(void) {
init_bldit();
lua_getglobal(B, "bldit_version");
if (!lua_isstring(B, -1)) {
@@ -456,7 +456,7 @@ char* bldit_getver() {
return strdup(bldit_version);
}
-char* bldit_pkg_getver() {
+char* bldit_pkg_getver(void) {
init_bldit();
lua_getglobal(B, "package_version");
if (!lua_isstring(B, -1)) {
@@ -618,7 +618,7 @@ bool bldit_uninstall(const char *target) {
return target_loop_success;
}
-void cache_repos() {
+void cache_repos(void) {
cached_repos_count = 0;
lua_getglobal(L, "repositories");
if (!config_loaded || !lua_istable(L, -1)) {
@@ -653,7 +653,7 @@ void cache_repos() {
lua_pop(L, 1);
}
-void cache_build_systems() {
+void cache_build_systems(void) {
if (!config_loaded) {
lua_getglobal(L, "build_systems");
} else if (!lua_istable(L, -1)) {
diff --git a/src/set_install_directories.c b/src/set_install_directories.c
index 7a4b59e..e7a62e0 100644
--- a/src/set_install_directories.c
+++ b/src/set_install_directories.c
@@ -26,7 +26,7 @@
#include "set_install_directories.h"
#include "vars.h"
-void set_install_directories() {
+void set_install_directories(void) {
lua_State *L = get_lua_state();
cache_prefix_directory();
lua_getglobal(L, "install_directories");
diff --git a/src/setup_dirs.c b/src/setup_dirs.c
index 02442c3..e675f2d 100644
--- a/src/setup_dirs.c
+++ b/src/setup_dirs.c
@@ -24,7 +24,7 @@
#include "setup_dirs.h"
#include "vars.h"
-void setup_dirs() {
+void setup_dirs(void) {
mkdir_p(config_dir);
for (int i = 0; i < 5; i++) {
if (install_directories[i] && strlen(install_directories[i]) <= 0) continue;
diff --git a/src/setup_pkgit.c b/src/setup_pkgit.c
index 31e3fd2..fa7404e 100644
--- a/src/setup_pkgit.c
+++ b/src/setup_pkgit.c
@@ -23,7 +23,7 @@
#include "set_install_directories.h"
#include "setup_dirs.h"
-void setup_pkgit() {
+void setup_pkgit(void) {
set_install_directories();
setup_dirs();
} \ No newline at end of file
diff --git a/src/update_all.c b/src/update_all.c
index 79b653c..756f98f 100644
--- a/src/update_all.c
+++ b/src/update_all.c
@@ -32,7 +32,7 @@
#include "lua_state.h"
#include "vars.h"
-void update_all() {
+void update_all(void) {
init_lua_state();
cache_repos();
struct dirent* dirent_ptr;
diff --git a/src/vars.c b/src/vars.c
index ba83559..b2694e9 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -56,7 +56,7 @@ size_t cached_repos_count = 0;
Map cached_build_systems = {0};
char home_config_buf[MAX_PATH_LEN] = {0};
-char *home_config() {
+char *home_config(void) {
snprintf(
home_config_buf, MAX_PATH_LEN,
"%s/.config/pkgit/init.lua",
@@ -76,37 +76,37 @@ const char *get_install_dir(const char *key) {
const char *version = "1.1.3";
-const char *red = "\e[0;31m";
-const char *green = "\e[0;32m";
-const char *yellow = "\e[0;33m";
-const char *blue = "\e[0;34m";
-const char *magenta = "\e[0;35m";
-const char *cyan = "\e[0;36m";
-const char *gray = "\e[0;37m";
-const char *bright_red = "\e[0;91m";
-const char *bright_green = "\e[0;92m";
-const char *bright_yellow = "\e[0;93m";
-const char *bright_blue = "\e[0;94m";
-const char *bright_magenta = "\e[0;95m";
-const char *bright_cyan = "\e[0;96m";
-const char *bright_gray = "\e[0;97m";
-const char *bold_red = "\e[1;31m";
-const char *bold_green = "\e[1;32m";
-const char *bold_yellow = "\e[1;33m";
-const char *bold_blue = "\e[1;34m";
-const char *bold_magenta = "\e[1;35m";
-const char *bold_cyan = "\e[1;36m";
-const char *bold_gray = "\e[1;37m";
-const char *bold_white = "\e[1;38m";
-const char *bold_bright_red = "\e[1;91m";
-const char *bold_bright_green = "\e[1;92m";
-const char *bold_bright_yellow = "\e[1;93m";
-const char *bold_bright_blue = "\e[1;94m";
-const char *bold_bright_magenta = "\e[1;95m";
-const char *bold_bright_cyan = "\e[1;96m";
-const char *bold_bright_gray = "\e[1;97m";
-const char *italic = "\e[3m";
-const char *color_reset = "\e[0m";
+const char *red = "\x1b[0;31m";
+const char *green = "\x1b[0;32m";
+const char *yellow = "\x1b[0;33m";
+const char *blue = "\x1b[0;34m";
+const char *magenta = "\x1b[0;35m";
+const char *cyan = "\x1b[0;36m";
+const char *gray = "\x1b[0;37m";
+const char *bright_red = "\x1b[0;91m";
+const char *bright_green = "\x1b[0;92m";
+const char *bright_yellow = "\x1b[0;93m";
+const char *bright_blue = "\x1b[0;94m";
+const char *bright_magenta = "\x1b[0;95m";
+const char *bright_cyan = "\x1b[0;96m";
+const char *bright_gray = "\x1b[0;97m";
+const char *bold_red = "\x1b[1;31m";
+const char *bold_green = "\x1b[1;32m";
+const char *bold_yellow = "\x1b[1;33m";
+const char *bold_blue = "\x1b[1;34m";
+const char *bold_magenta = "\x1b[1;35m";
+const char *bold_cyan = "\x1b[1;36m";
+const char *bold_gray = "\x1b[1;37m";
+const char *bold_white = "\x1b[1;38m";
+const char *bold_bright_red = "\x1b[1;91m";
+const char *bold_bright_green = "\x1b[1;92m";
+const char *bold_bright_yellow = "\x1b[1;93m";
+const char *bold_bright_blue = "\x1b[1;94m";
+const char *bold_bright_magenta = "\x1b[1;95m";
+const char *bold_bright_cyan = "\x1b[1;96m";
+const char *bold_bright_gray = "\x1b[1;97m";
+const char *italic = "\x1b[3m";
+const char *color_reset = "\x1b[0m";
const char *print_pkgit;
const char *print_success;
@@ -151,7 +151,7 @@ bool is_directory(const char *path) {
return S_ISDIR(statbuf.st_mode);
}
-void init_vars() {
+void init_vars(void) {
char *home = getenv("HOME");
if (home) snprintf(home_dir, MAX_PATH_LEN, "%s", home);
else snprintf(home_dir, MAX_PATH_LEN, "/root");