comparison common/system.h @ 0:1158cffe5a5e

Initial import
author David Demelier <markand@malikania.fr>
date Mon, 08 Feb 2016 16:43:14 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1158cffe5a5e
1 /*
2 * system.h -- platform dependent functions for system inspection
3 *
4 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef _IRCCD_SYSTEM_H_
20 #define _IRCCD_SYSTEM_H_
21
22 /**
23 * @file system.h
24 * @brief System dependant functions
25 */
26
27 #include <irccd-config.h>
28
29 #include <cstdint>
30 #include <string>
31
32 namespace irccd {
33
34 namespace sys {
35
36 /**
37 * Set the program name, needed for some functions or some systems.
38 *
39 * @param name the program name
40 */
41 void setProgramName(std::string name) noexcept;
42
43 /**
44 * Get the program name.
45 *
46 * @return the program name
47 */
48 const std::string &programName() noexcept;
49
50 /**
51 * Get the system name.
52 *
53 * @return the name
54 */
55 std::string name();
56
57 /**
58 * Get the system version.
59 *
60 * @return the version
61 */
62 std::string version();
63
64 /**
65 * Get the number of seconds elapsed since the boottime.
66 *
67 * @return the number of seconds
68 */
69 uint64_t uptime();
70
71 /**
72 * Get the milliseconds elapsed since the application
73 * startup.
74 *
75 * @return the milliseconds
76 */
77 uint64_t ticks();
78
79 /**
80 * Get an environment variable.
81 *
82 * @return the value or empty string
83 */
84 std::string env(const std::string &var);
85
86 /**
87 * Get home directory usually /home/foo
88 *
89 * @return the home directory
90 */
91 std::string home();
92
93 #if defined(HAVE_SETUID)
94
95 /**
96 * Set the effective uid by name or numeric value.
97 *
98 * @param value the value
99 */
100 void setUid(const std::string &value);
101
102 #endif
103
104 #if defined(HAVE_SETGID)
105
106 /**
107 * Set the effective gid by name or numeric value.
108 *
109 * @param value the value
110 */
111 void setGid(const std::string &value);
112
113 #endif
114
115 } // !sys
116
117 } // !irccd
118
119 #endif // !_IRCCD_SYSTEM_H_