Lolly 1.4.28
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
sys_utils.hpp File Reference
#include "array.hpp"
#include "string.hpp"
Include dependency graph for sys_utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  lolly
 

Macros

#define URL_CONCATER   '/'
 
#define URL_SEPARATOR   ':'
 

Functions

string get_env (string var)
 
void set_env (string var, string with)
 
string get_user_login ()
 
string get_user_name ()
 
bool os_win ()
 
bool os_mingw ()
 
bool os_macos ()
 
bool os_wasm ()
 
SN get_process_id ()
 
array< stringevaluate_system (array< string > arg, array< int > fd_in, array< string > in, array< int > fd_out)
 
void lolly::init_tbox ()
 
string lolly::get_stacktrace (unsigned int max_frames)
 

Macro Definition Documentation

◆ URL_CONCATER

#define URL_CONCATER   '/'

Definition at line 22 of file sys_utils.hpp.

◆ URL_SEPARATOR

#define URL_SEPARATOR   ':'

Definition at line 23 of file sys_utils.hpp.

Function Documentation

◆ get_env()

string get_env ( string var)

Definition at line 25 of file sys_utils.cpp.

25 {
27 tb_size_t size = 0;
28 string ret = string ("");
30 if (environment) {
32 if (size >= 1) {
33 tb_for_all_if (tb_char_t const*, value, environment, value) {
34 ret= ret * string (value) * URL_SEPARATOR;
35 }
36 }
37 }
39
40 if (size <= 0) {
41 return ret;
42 }
43 else {
44 return ret (0, N (ret) - 1);
45 }
46}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
The list class represents a linked list.
Definition list.hpp:48
#define URL_SEPARATOR
Definition sys_utils.hpp:23

◆ set_env()

void set_env ( string var,
string with )

Definition at line 49 of file sys_utils.cpp.

◆ get_user_login()

string get_user_login ( )

Definition at line 64 of file sys_utils.cpp.

64 {
65#if defined(OS_MINGW) || defined(OS_WIN)
66 return get_env ("USERNAME");
67#endif
68
69#if defined(OS_LINUX) || defined(OS_MACOS)
70 return unix_get_login ();
71#endif
72
73#if defined(OS_WASM)
74 return "wasm_user";
75#endif
76}
string get_env(string var)
Definition sys_utils.cpp:25
string unix_get_login()

◆ get_user_name()

string get_user_name ( )

Definition at line 79 of file sys_utils.cpp.

79 {
80#if defined(OS_MINGW) || defined(OS_WIN)
82#endif
83
84#if defined(OS_LINUX) || defined(OS_MACOS)
85 return unix_get_username ();
86#endif
87
88#if defined(OS_WASM)
89 return "wasm_user_name";
90#endif
91}
string win_get_username()
string unix_get_username()

◆ os_win()

bool os_win ( )

Definition at line 94 of file sys_utils.cpp.

94 {
95#if defined(OS_WIN)
96 return true;
97#else
98 return false;
99#endif
100}

◆ os_mingw()

bool os_mingw ( )

Definition at line 103 of file sys_utils.cpp.

103 {
104#ifdef OS_MINGW
105 return true;
106#else
107 return false;
108#endif
109}

◆ os_macos()

bool os_macos ( )

Definition at line 112 of file sys_utils.cpp.

112 {
113#if defined(OS_MACOS)
114 return true;
115#else
116 return false;
117#endif
118}

◆ os_wasm()

bool os_wasm ( )

Definition at line 121 of file sys_utils.cpp.

121 {
122#if defined(OS_WASM)
123 return true;
124#else
125 return false;
126#endif
127}

◆ get_process_id()

SN get_process_id ( )

Definition at line 130 of file sys_utils.cpp.

130 {
131#if defined(OS_MINGW) || defined(OS_WIN)
132 return win_get_process_id ();
133#endif
134
135#if defined(OS_MACOS) || defined(OS_LINUX)
136 return unix_get_process_id ();
137#endif
138
139#if defined(OS_WASM)
140 return 1;
141#endif
142}
SN unix_get_process_id()
SN win_get_process_id()

◆ evaluate_system()

array< string > evaluate_system ( array< string > arg,
array< int > fd_in,
array< string > in,
array< int > fd_out )

Definition at line 145 of file sys_utils.cpp.

146 {
147 array<string> out (N (fd_out));
149 for (int i= 0; i < N (fd_out); i++)
150 ptr[i]= &(out[i]);
151
152#if defined(OS_MINGW)
153 int ret= win_system (arg, fd_in, in, fd_out, ptr);
154#endif
155
156#if defined(OS_LINUX) || defined(OS_MACOS)
157 int ret= unix_system (arg, fd_in, in, fd_out, ptr);
158#endif
159
160#if defined(OS_WIN) || defined(OS_WASM)
161 int ret= -1;
162#endif
163
164 return append (as_string (ret), out);
165}
array< T > append(T a, array< T > b)
Append an element to the beginning of an array.
string as_string(int16_t i)
Definition string.cpp:272
int unix_system(array< string > arg, array< int > fd_in, array< string > str_in, array< int > fd_out, array< string * > str_out)