Changed variable names to more reasonable names and put declarations out of loops

This commit is contained in:
SpizzyCoder 2021-01-15 17:28:22 +01:00
parent 97adba0516
commit 683ff88015

View file

@ -48,33 +48,33 @@ void sig_handler(int signal) {
void detect_raspi(void) { void detect_raspi(void) {
bool raspi = false; bool raspi = false;
FILE *f = fopen("/sys/firmware/devicetree/base/model", "r"); FILE *DetectRaspi = fopen("/sys/firmware/devicetree/base/model", "r");
if (!f) { if (!DetectRaspi) {
return; return;
} }
char *line = NULL; char *line = NULL;
size_t line_size = 0; size_t line_size = 0;
while (getline(&line, &line_size, f) != -1) { while (getline(&line, &line_size, DetectRaspi) != -1) {
if (strstr(line, "Raspberry Pi")) { if (strstr(line, "Raspberry Pi")) {
raspi = true; raspi = true;
break; break;
} }
} }
fclose(f); fclose(DetectRaspi);
FILE *g = fopen("/proc/modules", "r"); FILE *DetectVc4 = fopen("/proc/modules", "r");
if (!g) { if (!DetectVc4) {
free(line); free(line);
return; return;
} }
bool vc4 = false; bool vc4 = false;
while (getline(&line, &line_size, g) != -1) { while (getline(&line, &line_size, DetectVc4) != -1) {
if (strstr(line, "vc4")) { if (strstr(line, "vc4")) {
vc4 = true; vc4 = true;
break; break;
} }
} }
free(line); free(line);
fclose(g); fclose(DetectVc4);
if (!vc4 && raspi) { if (!vc4 && raspi) {
fprintf(stderr, "\x1B[1;31mWarning: You have a " fprintf(stderr, "\x1B[1;31mWarning: You have a "
"Raspberry Pi, but the vc4 Module is " "Raspberry Pi, but the vc4 Module is "
@ -84,13 +84,13 @@ void detect_raspi(void) {
} }
void detect_proprietary(int allow_unsupported_gpu) { void detect_proprietary(int allow_unsupported_gpu) {
FILE *f = fopen("/proc/modules", "r"); FILE *DetectUnsupportedGpu = fopen("/proc/modules", "r");
if (!f) { if (!DetectUnsupportedGpu) {
return; return;
} }
char *line = NULL; char *line = NULL;
size_t line_size = 0; size_t line_size = 0;
while (getline(&line, &line_size, f) != -1) { while (getline(&line, &line_size, DetectUnsupportedGpu) != -1) {
if (strncmp(line, "nvidia ", 7) == 0) { if (strncmp(line, "nvidia ", 7) == 0) {
if (allow_unsupported_gpu) { if (allow_unsupported_gpu) {
sway_log(SWAY_ERROR, sway_log(SWAY_ERROR,
@ -118,7 +118,7 @@ void detect_proprietary(int allow_unsupported_gpu) {
} }
} }
free(line); free(line);
fclose(f); fclose(DetectUnsupportedGpu);
} }
void run_as_ipc_client(char *command, char *socket_path) { void run_as_ipc_client(char *command, char *socket_path) {
@ -157,6 +157,7 @@ static void log_file(FILE *f) {
} }
static void log_distro(void) { static void log_distro(void) {
FILE *path = NULL;
const char *paths[] = { const char *paths[] = {
"/etc/lsb-release", "/etc/lsb-release",
"/etc/os-release", "/etc/os-release",
@ -165,7 +166,7 @@ static void log_distro(void) {
"/etc/gentoo-release", "/etc/gentoo-release",
}; };
for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) {
FILE *f = fopen(paths[i], "r"); path = fopen(paths[i], "r");
if (f) { if (f) {
sway_log(SWAY_INFO, "Contents of %s:", paths[i]); sway_log(SWAY_INFO, "Contents of %s:", paths[i]);
log_file(f); log_file(f);
@ -175,13 +176,13 @@ static void log_distro(void) {
} }
static void log_kernel(void) { static void log_kernel(void) {
FILE *f = popen("uname -a", "r"); FILE *Kernel = popen("uname -a", "r");
if (!f) { if (!Kernel) {
sway_log(SWAY_INFO, "Unable to determine kernel version"); sway_log(SWAY_INFO, "Unable to determine kernel version");
return; return;
} }
log_file(f); log_file(Kernel);
pclose(f); pclose(Kernel);
} }
@ -273,8 +274,9 @@ int main(int argc, char **argv) {
"\n"; "\n";
int c; int c;
int option_index;
while (1) { while (1) {
int option_index = 0; option_index = 0;
c = getopt_long(argc, argv, "hCdD:vVc:", long_options, &option_index); c = getopt_long(argc, argv, "hCdD:vVc:", long_options, &option_index);
if (c == -1) { if (c == -1) {
break; break;