summaryrefslogtreecommitdiff
path: root/src/non_critical/_tools.c
blob: f152df27ddd71467c7ac14a78fcba064fb6b29ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.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;
}