diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-10-29 00:17:37 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-10-29 00:18:11 +0300 |
| commit | 6833ea062f264ff35773f23f6f68b293b4cfec34 (patch) | |
| tree | 94729c4364bc1a304e295b31cae89dca0b845832 /src/non_critical/_tools.c | |
| parent | d7c64d28e1bb3a9e8f563704128593da80b9f0a7 (diff) | |
Implemented some not critical functions.
Diffstat (limited to 'src/non_critical/_tools.c')
| -rw-r--r-- | src/non_critical/_tools.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/non_critical/_tools.c b/src/non_critical/_tools.c new file mode 100644 index 0000000..8c69d78 --- /dev/null +++ b/src/non_critical/_tools.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <string.h> + +int check_root() { + if(getuid() == 0) { + return 1; + } + return 0; +} + +int check_pid(int pid) { + if(getpid() == pid) { + return 1; + } + return 0; +} + + +char* get_os_name() { + FILE* file = fopen("/etc/os-release", "r"); + if (file == NULL) { + perror("fopen"); + return NULL; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char* name = strstr(line, "NAME="); + if (name != NULL) { + name += 5; // skip "NAME=" + char* end = strchr(name, '\n'); + if (end != NULL) { + *end = '\0'; + } + return name; + } + } + + fclose(file); + return NULL; +}
\ No newline at end of file |
