fix: dialogs library fixes, fix mangled name exports, fix libc exported by dialogs library

This commit is contained in:
2026-05-11 20:31:17 +02:00
parent b8d0f7fa42
commit af5094ac94
3 changed files with 67 additions and 102 deletions
+21 -32
View File
@@ -101,18 +101,20 @@ struct Runtime {
inline Runtime g_runtime = {};
inline bool ensure_handle(char* out_message, int out_message_len) {
if (g_runtime.handle) return true;
g_runtime.handle = libloader::dlopen(LIBRARY_PATH);
if (!g_runtime.handle) {
if (out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, "failed to load dialog library");
return false;
}
return true;
}
inline RunRequestFn resolve_run_request(char* out_message, int out_message_len) {
if (g_runtime.run_request) return g_runtime.run_request;
if (!g_runtime.handle) {
g_runtime.handle = libloader::dlopen(LIBRARY_PATH);
if (!g_runtime.handle) {
if (out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, "failed to load dialog library");
return nullptr;
}
}
if (!ensure_handle(out_message, out_message_len)) return nullptr;
g_runtime.run_request = (RunRequestFn)libloader::dlsym(g_runtime.handle, RUN_REQUEST_SYMBOL);
if (!g_runtime.run_request && out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, "failed to resolve dialog entry point");
@@ -121,23 +123,14 @@ inline RunRequestFn resolve_run_request(char* out_message, int out_message_len)
inline MessageBoxFn resolve_message_box(char* out_message, int out_message_len) {
if (g_runtime.message_box) return g_runtime.message_box;
if (!g_runtime.handle) {
g_runtime.handle = libloader::dlopen(LIBRARY_PATH);
if (!g_runtime.handle) {
if (out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, "failed to load dialog library");
return nullptr;
}
}
if (!ensure_handle(out_message, out_message_len)) return nullptr;
g_runtime.message_box = (MessageBoxFn)libloader::dlsym(g_runtime.handle, MESSAGE_BOX_SYMBOL);
if (!g_runtime.message_box && out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, "failed to resolve message box entry point");
return g_runtime.message_box;
}
inline bool run_request(const Request* req, Result* out_res, char* out_message, int out_message_len) {
inline bool run_request(const Request* req, Result& res, char* out_message, int out_message_len) {
if (out_message && out_message_len > 0) out_message[0] = '\0';
if (!req) {
if (out_message && out_message_len > 0)
@@ -145,21 +138,17 @@ inline bool run_request(const Request* req, Result* out_res, char* out_message,
return false;
}
Result local_res = {};
reset_result(&local_res);
RunRequestFn run_fn = resolve_run_request(out_message, out_message_len);
if (!run_fn) return false;
if (!run_fn(req, &local_res)) {
if (!run_fn(req, &res)) {
if (out_message && out_message_len > 0 && !out_message[0])
safe_copy(out_message, out_message_len, "dialog library invocation failed");
return false;
}
if (out_res) *out_res = local_res;
if (out_message && out_message_len > 0)
safe_copy(out_message, out_message_len, local_res.message);
return montauk::streq(local_res.status, "ok");
safe_copy(out_message, out_message_len, res.message);
return montauk::streq(res.status, "ok");
}
inline bool open_file(const char* title,
@@ -173,7 +162,7 @@ inline bool open_file(const char* title,
safe_copy(req.initial_path, sizeof(req.initial_path), initial_path);
Result res = {};
bool ok = run_request(&req, &res, out_message, out_message_len);
bool ok = run_request(&req, res, out_message, out_message_len);
if (ok && out_path && out_path_len > 0) safe_copy(out_path, out_path_len, res.path);
return ok;
}
@@ -191,7 +180,7 @@ inline bool save_file(const char* title,
safe_copy(req.suggested_name, sizeof(req.suggested_name), suggested_name);
Result res = {};
bool ok = run_request(&req, &res, out_message, out_message_len);
bool ok = run_request(&req, res, out_message, out_message_len);
if (ok && out_path && out_path_len > 0) safe_copy(out_path, out_path_len, res.path);
return ok;
}
@@ -210,7 +199,7 @@ inline bool print_file(const char* title,
safe_copy(req.job_name, sizeof(req.job_name), job_name);
Result res = {};
bool ok = run_request(&req, &res, out_message, out_message_len);
bool ok = run_request(&req, res, out_message, out_message_len);
if (ok && out_job_id && out_job_id_len > 0) safe_copy(out_job_id, out_job_id_len, res.job_id);
return ok;
}
@@ -231,7 +220,7 @@ inline bool configure_print(const char* title,
safe_copy(req.printer_uri, sizeof(req.printer_uri), initial_printer_uri);
Result res = {};
bool ok = run_request(&req, &res, out_message, out_message_len);
bool ok = run_request(&req, res, out_message, out_message_len);
if (ok && out_printer_uri && out_printer_uri_len > 0) safe_copy(out_printer_uri, out_printer_uri_len, res.printer_uri);
if (ok && out_printer_name && out_printer_name_len > 0) safe_copy(out_printer_name, out_printer_name_len, res.printer_name);
if (ok && out_copies) *out_copies = res.copies > 0 ? res.copies : 1;