Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions
sysdep.h File Reference
#include "lib/debug.h"
#include "lib/os_path.h"
#include <cstdarg>

Go to the source code of this file.

Macros

#define SYS_DIR_SEP   '/'
 directory separation character More...
 

Functions

void sys_display_msg (const wchar_t *caption, const wchar_t *msg)
 display a message. More...
 
ErrorReactionInternal sys_display_error (const wchar_t *text, size_t flags)
 show the error dialog. More...
 
LIB_API bool sys_IsDebuggerPresent ()
 
LIB_API std::wstring sys_WideFromArgv (const char *argv_i)
 
int sys_vswprintf (wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr)
 sys_vswprintf: doesn't quite follow the standard for vswprintf, but works better across compilers: More...
 
Status sys_StatusDescription (int err, wchar_t *buf, size_t max_chars)
 describe the current OS error state. More...
 
Status sys_get_module_filename (void *addr, OsPath &pathname)
 determine filename of the module to whom an address belongs. More...
 
LIB_API OsPath sys_ExecutablePathname ()
 
std::wstring sys_get_user_name ()
 Get the current user's login name. More...
 
Status sys_pick_directory (OsPath &path)
 Have the user choose a directory via OS dialog. More...
 
Status sys_open_url (const std::string &url)
 Open the user's default web browser to the given URL. More...
 
size_t sys_max_sector_size ()
 return the largest sector size [bytes] of any storage medium (HD, optical, etc.) in the system. More...
 
LIB_API Status sys_generate_random_bytes (u8 *buf, size_t count)
 generate high-quality random bytes. More...
 
LIB_API Status sys_get_proxy_config (const std::wstring &url, std::wstring &proxy)
 get the proxy address for accessing the given HTTP URL. More...
 
LIB_API FILE * sys_OpenFile (const OsPath &pathname, const char *mode)
 open a file like with fopen (but taking an OsPath argument). More...
 

Macro Definition Documentation

#define SYS_DIR_SEP   '/'

directory separation character

Definition at line 196 of file sysdep.h.

Function Documentation

ErrorReactionInternal sys_display_error ( const wchar_t text,
size_t  flags 
)

show the error dialog.

Parameters
textto display (practically unlimited length)
flags,:see DebugDisplayErrorFlags.
Returns
ErrorReactionInternal (except ERI_EXIT, which is acted on immediately)

called from debug_DisplayError unless overridden by means of ah_display_error.

Definition at line 202 of file unix.cpp.

void sys_display_msg ( const wchar_t caption,
const wchar_t msg 
)

display a message.

Parameters
captiontitle message
msgmessage contents

implemented as a MessageBox on Win32 and printf on Unix. called from debug_DisplayMessage.

Definition at line 60 of file unix.cpp.

LIB_API OsPath sys_ExecutablePathname ( )
Returns
full pathname of the current executable.

this is useful for determining installation directory, e.g. for VFS.

Definition at line 33 of file bsd.cpp.

LIB_API Status sys_generate_random_bytes ( u8 buf,
size_t  count 
)

generate high-quality random bytes.

this should only be used with small numbers of bytes, to avoid hogging the system's entropy.

Definition at line 318 of file unix.cpp.

Status sys_get_module_filename ( void *  addr,
OsPath pathname 
)

determine filename of the module to whom an address belongs.

Parameters
addr
pathnameFull path to module (unchanged unless INFO::OK is returned).
Returns
Status

note: this is useful for handling exceptions in other modules.

Definition at line 384 of file wsysdep.cpp.

LIB_API Status sys_get_proxy_config ( const std::wstring &  url,
std::wstring &  proxy 
)

get the proxy address for accessing the given HTTP URL.

this may be very slow (tens of seconds).

Returns
INFO::OK on success; INFO::SKIPPED if no proxy found.

Definition at line 338 of file unix.cpp.

std::wstring sys_get_user_name ( )

Get the current user's login name.

Returns
login name, or empty string on error

Definition at line 295 of file unix.cpp.

LIB_API bool sys_IsDebuggerPresent ( )
Returns
whether a debugger is attached to the process (if so, it is safe to use debug_break; otherwise, that would raise an exception)

Definition at line 46 of file unix.cpp.

size_t sys_max_sector_size ( )

return the largest sector size [bytes] of any storage medium (HD, optical, etc.) in the system.

this may be a bit slow to determine (iterates over all drives), but caches the result so subsequent calls are free. (caveat: device changes won't be noticed during this program run)

sector size is relevant because Windows aio requires all IO buffers, offsets and lengths to be a multiple of it. this requirement is also carried over into the vfs / file.cpp interfaces for efficiency (avoids the need for copying to/from align buffers).

waio uses the sector size to (in some cases) align IOs if they aren't already, but it's also needed by user code when aligning their buffers to meet the requirements.

the largest size is used so that we can read from any drive. while this is a bit wasteful (more padding) and requires iterating over all drives, it is the only safe way: this may be called before we know which drives will be needed, and hardlinks may confuse things.

Definition at line 286 of file unix.cpp.

Status sys_open_url ( const std::string &  url)

Open the user's default web browser to the given URL.

Definition at line 343 of file unix.cpp.

LIB_API FILE* sys_OpenFile ( const OsPath pathname,
const char *  mode 
)

open a file like with fopen (but taking an OsPath argument).

Definition at line 373 of file unix.cpp.

Status sys_pick_directory ( OsPath path)

Have the user choose a directory via OS dialog.

Parameters
pathPath's input value determines the starting directory for faster browsing. if INFO::OK is returned, it receives chosen directory path.

Definition at line 428 of file wsysdep.cpp.

Status sys_StatusDescription ( int  err,
wchar_t buf,
size_t  max_chars 
)

describe the current OS error state.

Parameters
err,:if not 0, use that as the error code to translate; otherwise, uses GetLastError or similar.
bufoutput buffer
max_charsrationale: it is expected to be rare that OS return/error codes are actually seen by user code, but we leave the possibility open.

Definition at line 271 of file unix.cpp.

int sys_vswprintf ( wchar_t buffer,
size_t  count,
const wchar_t format,
va_list  argptr 
)

sys_vswprintf: doesn't quite follow the standard for vswprintf, but works better across compilers:

  • handles positional parameters and lld
  • always null-terminates the buffer, if count > 0
  • returns -1 on overflow (if the output string (including null) does not fit in the buffer)

Definition at line 30 of file printf.cpp.

LIB_API std::wstring sys_WideFromArgv ( const char *  argv_i)
Returns
a wide string conversion of the platform's encoding of main's argv.

(NB: wseh.cpp defines a wmain that converts argv to UTF-8 and calls main(), but only if LIB_STATIC_LINK)

Definition at line 51 of file unix.cpp.