mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-03-18 00:45:59 +08:00
waver : bump version to v1.3.2
- single-threaded app - new message indicator - audio capture indicator - emscripten compatibility
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
#include "ggwave-common.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
|
||||
namespace {
|
||||
void dummy() {}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> parseCmdArguments(int argc, char ** argv) {
|
||||
int last = argc;
|
||||
@@ -15,3 +24,53 @@ std::map<std::string, std::string> parseCmdArguments(int argc, char ** argv) {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<char> readFile(const char* filename) {
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
if (!file.is_open() || !file.good()) return {};
|
||||
|
||||
file.unsetf(std::ios::skipws);
|
||||
std::streampos fileSize;
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<char> vec;
|
||||
vec.reserve(fileSize);
|
||||
|
||||
vec.insert(vec.begin(),
|
||||
std::istream_iterator<char>(file),
|
||||
std::istream_iterator<char>());
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
std::string getBinaryPath() {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return "";
|
||||
#endif
|
||||
std::string result;
|
||||
void* p = reinterpret_cast<void*>(dummy);
|
||||
|
||||
Dl_info info;
|
||||
dladdr(p, &info);
|
||||
|
||||
if (*info.dli_fname == '/') {
|
||||
result = info.dli_fname;
|
||||
} else {
|
||||
char buff[2048];
|
||||
auto len = readlink("/proc/self/exe", buff, sizeof(buff) - 1);
|
||||
if (len > 0) {
|
||||
buff[len] = 0;
|
||||
result = buff;
|
||||
}
|
||||
}
|
||||
|
||||
auto slash = result.rfind('/');
|
||||
if (slash != std::string::npos) {
|
||||
result.erase(slash + 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user