minecraft-pi-reborn/launcher/src/ldconfig.cpp

58 lines
1.6 KiB
C++
Raw Normal View History

2021-06-17 21:32:24 +00:00
#include <unistd.h>
#include <string>
#include <cstring>
#include <cstdio>
2022-03-14 23:09:25 +00:00
#include <sstream>
2021-06-17 21:32:24 +00:00
#include <libreborn/libreborn.h>
#include "ldconfig.h"
char *get_full_library_search_path() {
2022-03-14 23:09:25 +00:00
std::string processed_output;
2021-06-17 21:32:24 +00:00
// Run
2022-03-14 23:09:25 +00:00
int return_code;
const char *ldconfig_argv[] = {"/sbin/ldconfig", "-NXv", NULL};
char *output = run_command(ldconfig_argv, &return_code);
std::stringstream output_stream((std::string(output)));
// Check Exit Code
if (return_code != 0) {
ERR("ldconfig Failed: Exit Code: %i", return_code);
}
2021-06-17 21:32:24 +00:00
// Read
int running = 1;
while (running) {
2022-03-14 23:09:25 +00:00
std::string line;
if (std::getline(output_stream, line)) {
2021-06-17 21:32:24 +00:00
// Remove Newline
2022-03-14 23:09:25 +00:00
if (line.size() > 0 && line[line.size() - 1] == '\n') {
line.pop_back();
2021-06-17 21:32:24 +00:00
}
// Interpret
2022-03-14 23:09:25 +00:00
if (line.size() >= 2 && line[0] != '\t' && line[line.size() - 1] == ':') {
2022-03-13 03:52:58 +00:00
// Blacklist RPI Legacy GL Drivers
#define RPI_LEGACY_GL_PATH "/opt/vc"
2022-03-14 23:09:25 +00:00
if (line.rfind(RPI_LEGACY_GL_PATH ":", 0) != 0 && line.rfind(RPI_LEGACY_GL_PATH "/", 0) != 0) {
processed_output.append(line);
2022-03-13 03:52:58 +00:00
}
2021-06-17 21:32:24 +00:00
}
} else {
running = 0;
}
}
2022-03-14 23:09:25 +00:00
// Free Output
free(output);
2021-06-17 21:32:24 +00:00
// Remove Colon
2022-03-14 23:09:25 +00:00
if (processed_output.size() > 0 && processed_output[processed_output.size() - 1] == ':') {
processed_output.pop_back();
2022-03-09 23:47:31 +00:00
}
2022-03-14 23:09:25 +00:00
2021-06-17 21:32:24 +00:00
// Return
2022-03-14 23:09:25 +00:00
char *output_str = strdup(processed_output.c_str());
2021-06-17 21:32:24 +00:00
ALLOC_CHECK(output_str);
return output_str;
}