3709192002-03-20Martin Nilsson #pike __REAL_VERSION__
29a20a2003-04-27Martin Nilsson #pragma strict_types
3709192002-03-20Martin Nilsson 
29a20a2003-04-27Martin Nilsson // This module is to allow the _system module to be called System.
d8d4a42001-04-29Mirar (Pontus Hagland) 
fc398b2001-05-31Fredrik Hübinette (Hubbe) inherit _system;
832dd62002-02-21Per Hedbor  constant Timer = __builtin.Timer; constant Time = __builtin.Time;
379f922013-05-27Per Hedbor #if constant(__builtin.TM)
12327f2013-05-22Per Hedbor constant TM = __builtin.TM;
379f922013-05-27Per Hedbor #endif
4410592012-07-15Bill Welliver //! Get the username of the user that started the process. //! //! @returns //! the username of the user "associated" with the current process, or zero //! if a method to find this information does not exist on the current system.
9c93752012-07-15Bill Welliver //! //! @note
4410592012-07-15Bill Welliver //! On NT systems, this returns the user the current thread is running as, //! while on Unix-like systems this function returns the user that started //! the process (rather than the effective user)..
9c93752012-07-15Bill Welliver string get_user() { #if constant(System.GetUserName) return System.GetUserName();
f6bb672012-07-15Bill Welliver #elseif constant(getuid) return [string]getpwuid(getuid())[0];
9c93752012-07-15Bill Welliver #else
4410592012-07-15Bill Welliver  return 0;
f6bb672012-07-15Bill Welliver #endif
9c93752012-07-15Bill Welliver } //! Get the full path for the current user's home directory
4410592012-07-15Bill Welliver //! //! @returns //! the full path to the current user's home directory, or zero //! if the appropriate environment variables have not been set. //! //! @note //! This method uses the standard environment variables for //! various systems to determine the home directory.
9c93752012-07-15Bill Welliver string get_home() {
976cfb2012-07-15Bill Welliver  string home = [string]getenv("HOME");
9c93752012-07-15Bill Welliver  if(home) return home; #if __NT__
976cfb2012-07-15Bill Welliver  string homedrive = [string]getenv("HOMEDRIVE"); home = [string]getenv("HOMEPATH");
9c93752012-07-15Bill Welliver  if(homedrive)
4410592012-07-15Bill Welliver  home = combine_path(homedrive + "\\", (home||"\\"));
9c93752012-07-15Bill Welliver  if(home) return home; #endif
976cfb2012-07-15Bill Welliver  return 0;
9c93752012-07-15Bill Welliver }