icedb  version 0.5.1
Snow particle scattering database API
Namespaces | Functions
icedb::os_functions Namespace Reference

Namespaces

 unix
 
 vars
 
 win
 

Functions

bool populateOSstrings ()
 
bool pidExists (int pid)
 
int getPID ()
 
int getPPID (int pid)
 
void libEntry (int argc, char **argv)
 
void waitOnExit (bool val)
 
bool waitOnExit ()
 
const char * getUserName ()
 
const char * getHostName ()
 
const char * getAppConfigDir ()
 
const char * getHomeDir ()
 
const char * getLibDir ()
 
const char * getAppDir ()
 
const char * getPluginDir ()
 
const char * getLibPath ()
 
const char * getAppPath ()
 
const char * getCWD ()
 

Function Documentation

◆ getAppConfigDir()

DL_ICEDB const char * icedb::os_functions::getAppConfigDir ( )
See also
ICEDB_getAppConfigDir

Definition at line 946 of file os_functions.cpp.

References ICEDB_getAppConfigDir().

946 { return ICEDB_getAppConfigDir(); }
const char * ICEDB_getAppConfigDir()
Here is the call graph for this function:

◆ getAppDir()

DL_ICEDB const char * icedb::os_functions::getAppDir ( )

Definition at line 949 of file os_functions.cpp.

References icedb::os_functions::vars::appDir, and ICEDB_getAppDirI().

949 { ICEDB_getAppDirI(); return appDir.c_str(); }
void ICEDB_getAppDirI()
Here is the call graph for this function:

◆ getAppPath()

DL_ICEDB const char * icedb::os_functions::getAppPath ( )

Definition at line 952 of file os_functions.cpp.

References icedb::os_functions::vars::appPath, and ICEDB_getAppDirI().

952 { ICEDB_getAppDirI(); return appPath.c_str(); }
void ICEDB_getAppDirI()
Here is the call graph for this function:

◆ getCWD()

DL_ICEDB const char * icedb::os_functions::getCWD ( )

Definition at line 953 of file os_functions.cpp.

References icedb::os_functions::vars::CWD, and ICEDB_getCWDI().

953 { ICEDB_getCWDI(); return CWD.c_str(); }
void ICEDB_getCWDI()
Here is the call graph for this function:

◆ getHomeDir()

DL_ICEDB const char * icedb::os_functions::getHomeDir ( )
See also
ICEDB_getHomeDir

Definition at line 947 of file os_functions.cpp.

References ICEDB_getHomeDir().

947 { return ICEDB_getHomeDir(); }
const char * ICEDB_getHomeDir()
Here is the call graph for this function:

◆ getHostName()

DL_ICEDB const char * icedb::os_functions::getHostName ( )
See also
ICEDB_getHostName

Definition at line 945 of file os_functions.cpp.

References ICEDB_getHostName().

945 { return ICEDB_getHostName(); }
const char * ICEDB_getHostName()
Here is the call graph for this function:

◆ getLibDir()

DL_ICEDB const char * icedb::os_functions::getLibDir ( )

Definition at line 948 of file os_functions.cpp.

References ICEDB_getLibDirI(), and icedb::os_functions::vars::libDir.

948 { ICEDB_getLibDirI(); return libDir.c_str(); }
void ICEDB_getLibDirI()
Here is the call graph for this function:

◆ getLibPath()

DL_ICEDB const char * icedb::os_functions::getLibPath ( )

Definition at line 951 of file os_functions.cpp.

References ICEDB_getLibDirI(), and icedb::os_functions::vars::libPath.

951 { ICEDB_getLibDirI(); return libPath.c_str(); }
void ICEDB_getLibDirI()
Here is the call graph for this function:

◆ getPID()

DL_ICEDB int icedb::os_functions::getPID ( )
See also
ICEDB_getPID

Definition at line 939 of file os_functions.cpp.

References ICEDB_getPID().

Referenced by ICEDB_enumModules().

939 { return ICEDB_getPID(); }
int ICEDB_getPID()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPluginDir()

DL_ICEDB const char * icedb::os_functions::getPluginDir ( )

Definition at line 950 of file os_functions.cpp.

References ICEDB_getPluginDirI(), and icedb::os_functions::vars::pluginDir.

950 { ICEDB_getPluginDirI(); return pluginDir.c_str(); }
void ICEDB_getPluginDirI()
Here is the call graph for this function:

◆ getPPID()

DL_ICEDB int icedb::os_functions::getPPID ( int  pid)
See also
ICEDB_getPPID

Definition at line 940 of file os_functions.cpp.

References ICEDB_getPPID().

940 { return ICEDB_getPPID(pid); }
int ICEDB_getPPID(int pid)
Here is the call graph for this function:

◆ getUserName()

DL_ICEDB const char * icedb::os_functions::getUserName ( )
See also
ICEDB_getUserName

Definition at line 944 of file os_functions.cpp.

References ICEDB_getUserName().

944 { return ICEDB_getUserName(); }
const char * ICEDB_getUserName()
Here is the call graph for this function:

◆ libEntry()

DL_ICEDB void icedb::os_functions::libEntry ( int  argc,
char **  argv 
)
See also
ICEDB_libEntry

Definition at line 941 of file os_functions.cpp.

References ICEDB_libEntry().

941 { ICEDB_libEntry(argc, argv); }
void ICEDB_libEntry(int, char **)
Entry function that gets called when a debugged application first loads.
Here is the call graph for this function:

◆ pidExists()

DL_ICEDB bool icedb::os_functions::pidExists ( int  pid)
See also
ICEDB_pidExists

Definition at line 938 of file os_functions.cpp.

References ICEDB_pidExists().

938 { bool res = false; ICEDB_pidExists(pid, res); return res; }
bool ICEDB_pidExists(int pid, bool &res)
Here is the call graph for this function:

◆ populateOSstrings()

bool icedb::os_functions::populateOSstrings ( )

Definition at line 265 of file os_functions.cpp.

References icedb::os_functions::vars::appConfigDir, icedb::os_functions::vars::homeDir, icedb::os_functions::vars::hostname, ICEDB_error_context_add_string2, ICEDB_error_context_create, ICEDB_error_getOSname, ICEDB_ERRORCODES_OS, ICEDB_ERRORCODES_UNIMPLEMENTED, ICEDB_free(), ICEDB_malloc(), icedb::os_functions::vars::m_sys_names, and icedb::os_functions::vars::username.

Referenced by ICEDB_getAppConfigDir(), ICEDB_getHomeDir(), ICEDB_getHostName(), and ICEDB_getUserName().

265  {
266  using namespace icedb::os_functions::vars;
267  std::lock_guard<std::mutex> lock(m_sys_names);
268  // Because of the mutex lock, all of the getlogin functions are safe.
269  if (username.size()) return true;
270 
271  // Username
272 #if defined(ICEDB_OS_WINDOWS)
273  BOOL res = false;
274  const DWORD clen = 256;
275  DWORD len = clen;
276  TCHAR hname[clen];
277  res = GetUserName(hname, &len);
278  if (res) username = win::convertStr(hname);
279  else goto funcErrorOS;
280 
281  res = GetComputerName(hname, &len);
282  if (res) hostname = win::convertStr(hname);
283  else goto funcErrorOS;
284 
285  HRESULT resl = false;
286  wchar_t* happname = nullptr;
287  res = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &happname);
288  if (resl == S_OK) appConfigDir = win::convertStr(happname);
289  else goto funcErrorOS;
290 
291  wchar_t* hhomename = nullptr;
292  res = SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &hhomename);
293  if (resl == S_OK) homeDir = win::convertStr(hhomename);
294  else goto funcErrorOS;
295 
296  goto done;
297  funcErrorOS:
298  DWORD errn = GetLastError();
300  const char* osname = ICEDB_error_getOSname();
301  ICEDB_error_context_add_string2(err, "OS_id", osname);
302  char errns[50];
303  snprintf(errns, 50, "%d", errn);
304  ICEDB_error_context_add_string2(err, "OS_errno", errns);
305  if (!username.size()) ICEDB_error_context_add_string2(err, "OS_func", "GetUserName");
306  else if (!hostname.size()) ICEDB_error_context_add_string2(err, "OS_func", "GetComputerName");
307  else if (!appConfigDir.size()) ICEDB_error_context_add_string2(err, "OS_func", "SHGetKnownFolderPath app config dir");
308  else if (!homeDir.size()) ICEDB_error_context_add_string2(err, "OS_func", "SHGetKnownFolderPath profile dir");
309  done:
310  if (happname) CoTaskMemFree(static_cast<void*>(happname));
311  if (hhomename) CoTaskMemFree(static_cast<void*>(hhomename));
312 
313 #elif defined(__unix__) || defined(__APPLE__)
314  const size_t len = 65536;
315  char hname[len];
316  int res = 0;
317  char* envres = NULL;
318 
319  if ((envres = getenv("USER"))) username = std::string(envres);
320  else if ((envres = getenv("LOGNAME"))) username = std::string(envres);
321  if (!username.size()) {
322 #if defined(_POSIX_C_SOURCE)
323 #if _POSIX_C_SOURCE >= 199506L
324  res = getlogin_r(hname, len); // getlogin and getlogin_r have problems. Avoid.
325  if (!res) username = std::string(hname);
326 #else
327  if ((envres = getlogin())) username = std::string(envres);
328 #endif
329  // Has getpwuid_r
330  if (!username.size()) {
331  uid_t uid = geteuid();
332  struct passwd* ps = (passwd*) ICEDB_malloc(sizeof(passwd));
333  struct passwd** pres; // A pointer to the result (or NULL on failure) is stored here.
334  res = getpwuid_r(uid, ps, hname, len, pres);
335  if ((res == 0) && pres) {
336  username = std::string(ps->pw_name);
337  }
338 
339  ICEDB_free(ps);
340  }
341 #else
342  // May have getpwuid
343  uid_t uid = geteuid();
344  struct passwd* ps = getpwuid(uid);
345  if (ps) username = std::string(ps->pw_name);
346 #endif
347  }
348 
349  // Hostname
350  res = gethostname(hname, len); // May be empty
351  if (hname[0]) hostname = std::string(hname);
352 
353  // Home dir
354  if ((envres = getenv("HOME"))) homeDir = std::string(envres);
355  if (!homeDir.size())
356  {
357 #if defined(_POSIX_C_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE)
358  struct passwd pw, *pwp;
359  int res = getpwuid_r(geteuid(), &pw, hname, len, &pwp);
360  if (res == 0) {
361  const char *homedir = pw.pw_dir;
362  homeDir = std::string(homedir);
363  }
364 #else
365  struct passwd* ps = getpwuid(geteuid());
366  if (ps) homeDir = std::string(ps->pw_dir);
367 #endif
368  }
369  if (!homeDir.size()) goto funcErrorOS;
370 
371  // App config dir
372  if ((envres = getenv("XDG_CONFIG_HOME"))) appConfigDir = std::string(envres);
373  else {
375  appConfigDir.append("/.config");
376  }
377 
378  goto done;
379  funcErrorOS:
380  {
382  const char* osname = ICEDB_error_getOSname();
383  ICEDB_error_context_add_string2(err, "OS_id", osname);
384  if (!username.size()) ICEDB_error_context_add_string2(err, "OS_func", "getlogin_r");
385  else if (!hostname.size()) ICEDB_error_context_add_string2(err, "OS_func", "gethostname");
386  else if (!appConfigDir.size()) ICEDB_error_context_add_string2(err, "OS_func", "getEnviron app config dir");
387  else if (!homeDir.size()) ICEDB_error_context_add_string2(err, "OS_func", "getEnviron profile dir");
388  }
389  done:
390 
391 #endif
393  const char* cosname = ICEDB_error_getOSname();
394  ICEDB_error_context_add_string2(ctxerr, "OS_id", cosname);
395  return false;
396  }
ICEDB_SYMBOL_SHARED void ICEDB_free(void *obj)
Free memory region. Should not be double-freed.
Definition: util.cpp:97
Unimplemented function path.
Definition: errorCodes.h:18
DL_ICEDB ICEDB_error_getOSname_f ICEDB_error_getOSname
Definition: error.cpp:210
ICEDB_SYMBOL_SHARED void * ICEDB_malloc(size_t numBytes)
Allocate memory in bytes. Generally this is just malloced, but a custom allocator may be substituted...
Definition: util.cpp:90
Error returned by an os subsystem (general)
Definition: errorCodes.h:17
#define ICEDB_error_context_add_string2
Definition: error_context.h:63
#define ICEDB_error_context_create(x)
Definition: error_context.h:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitOnExit() [1/2]

DL_ICEDB void icedb::os_functions::waitOnExit ( bool  val)
See also
ICEDB_waitOnExitSet

Definition at line 942 of file os_functions.cpp.

References ICEDB_waitOnExitSet().

942 { ICEDB_waitOnExitSet(val); }
void ICEDB_waitOnExitSet(bool val)
Here is the call graph for this function:

◆ waitOnExit() [2/2]

DL_ICEDB bool icedb::os_functions::waitOnExit ( )
See also
ICEDB_waitOnExitGet

Definition at line 943 of file os_functions.cpp.

References ICEDB_waitOnExitGet().

943 { return ICEDB_waitOnExitGet(); }
bool ICEDB_waitOnExitGet()
Here is the call graph for this function: