23 #include "precompiled.h"
33 #include <boost/algorithm/string/replace.hpp>
41 #define URL_OPEN_COMMAND "open"
43 #define URL_OPEN_COMMAND "xdg-open"
62 fprintf(stderr,
"%ls: %ls\n", caption, msg);
65 #if OS_MACOSX || OS_ANDROID
87 boost::algorithm::replace_all(message,
"\r\n",
"\n");
93 const char* cmd =
"/usr/bin/xmessage";
95 char buttons[256] =
"";
96 const char* defaultButton =
"Exit";
100 strcat_s(buttons,
sizeof(buttons),
"Continue:100,");
101 defaultButton =
"Continue";
105 strcat_s(buttons,
sizeof(buttons),
"Suppress:101,");
107 strcat_s(buttons,
sizeof(buttons),
"Break:102,Debugger:103,Exit:104");
112 char*
const argv[] = {
114 strdup(
"-geometry"), strdup(
"x500"),
115 strdup(
"-title"), strdup(
"0 A.D. message"),
116 strdup(
"-buttons"), strdup(buttons),
117 strdup(
"-default"), strdup(defaultButton),
118 strdup(message.c_str()),
157 for(
char*
const* a = argv; *a; ++a)
161 waitpid(cpid, &status, 0);
164 if(!WIFEXITED(status))
167 switch(WEXITSTATUS(status))
229 printf(
"(C)ontinue, ");
231 printf(
"(S)uppress, ");
232 printf(
"(B)reak, Launch (D)ebugger, or (E)xit?\n");
289 static size_t cached_sector_size;
290 if(!cached_sector_size)
291 cached_sector_size = sysconf(_SC_PAGE_SIZE);
292 return cached_sector_size;
299 const char* logname = getenv(
"LOGNAME");
300 if (logname && strcmp(logname,
"") != 0)
301 return std::wstring(logname, logname + strlen(logname));
305 #warning TODO: sys_get_user_name: do something more appropriate and more thread-safe
306 char* buf = getlogin();
308 return std::wstring(buf, buf + strlen(buf));
312 return std::wstring(buf, buf + strlen(buf));
320 FILE* f = fopen(
"/dev/urandom",
"rb");
326 size_t numread = fread(buf, 1, count, f);
375 return fopen(
OsString(pathname).c_str(), mode);
std::wstring sys_get_user_name()
Get the current user's login name.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
int setenv(const char *envname, const char *envval, int overwrite)
rationale: the Windows headers declare many POSIX functions (e.g.
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
enable the Suppress button.
special return value for the display_error app hook stub to indicate that it has done nothing and tha...
ErrorReactionInternal sys_display_error(const wchar_t *text, size_t flags)
show the error dialog.
Status sys_get_proxy_config(const std::wstring &url, std::wstring &proxy)
get the proxy address for accessing the given HTTP URL.
size_t sys_max_sector_size()
return the largest sector size [bytes] of any storage medium (HD, optical, etc.) in the system...
static ErrorReactionInternal try_gui_display_error(const wchar_t *text, bool manual_break, bool allow_suppress, bool no_continue)
FILE * sys_OpenFile(const OsPath &pathname, const char *mode)
open a file like with fopen (but taking an OsPath argument).
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
exit the program immediately.
Status sys_StatusDescription(int err, wchar_t *buf, size_t max_chars)
describe the current OS error state.
Status sys_open_url(const std::string &url)
Open the user's default web browser to the given URL.
void sys_display_msg(const wchar_t *caption, const wchar_t *msg)
display a message.
int strcat_s(char *dst, size_t max_dst_chars, const char *src)
std::wstring sys_WideFromArgv(const char *argv_i)
i64 Status
Error handling system.
void debug_break()
trigger a breakpoint when reached/"called".
disallow the Continue button.
Status sys_generate_random_bytes(u8 *buf, size_t count)
generate high-quality random bytes.
do not trigger a breakpoint inside debug_DisplayError; caller will take care of this if ER_BREAK is r...
std::wstring wstring_from_utf8(const std::string &src, Status *err)
convert UTF-8 to a wide string (UTF-16 or UCS-4, depending on the platform's wchar_t).
bool sys_IsDebuggerPresent()
ignore and do not report again.
#define WARN_RETURN(status)
#define debug_warn(expr)
display the error dialog with the given text.
void udbg_launch_debugger()
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
static std::string OsString(const OsPath &path)
ErrorReactionInternal
all choices offered by the error dialog.