1 #ifndef DINIT_OPTIONS_PROCESSING_H
2 #define DINIT_OPTIONS_PROCESSING_H 1
6 // A service directory entry, tracking the directory as a nul-terminated string, which may either
7 // be static or dynamically allocated (via new char[...]).
11 bool dir_dyn_allocd; // dynamically allocated?
14 dir_entry(const char *dir_p, bool dir_dyn_allocd_p) :
15 dir(dir_p), dir_dyn_allocd(dir_dyn_allocd_p)
18 dir_entry(dir_entry &&other)
21 dir_dyn_allocd = other.dir_dyn_allocd;
22 other.dir_dyn_allocd = false;
25 dir_entry(const dir_entry &other) = delete;
34 const char *get_dir() const
40 // TODO this is close to just being a vector; make it so?
41 class service_dir_pathlist
43 std::vector<dir_entry> service_dirs; // directories containing service descriptions
46 service_dir_pathlist() { }
48 service_dir_pathlist(const char *service_dir_p, bool dyn_allocd = false)
50 service_dirs.emplace_back(service_dir_p, dyn_allocd);
53 void add_dir(const char *service_dir_p, bool dyn_allocd = false)
55 service_dirs.emplace_back(service_dir_p, dyn_allocd);
60 return service_dirs.size();
63 dir_entry &operator[](size_t index)
65 return service_dirs[index];
68 std::vector<dir_entry>::iterator begin()
70 return service_dirs.begin();
73 std::vector<dir_entry>::iterator end()
75 return service_dirs.end();
81 const char *service_dir = nullptr;;
82 bool service_dir_dynamic = false;
86 static const char *user_home_path;
88 service_dir_pathlist service_dir_paths;
91 // Get user home (and set user_home_path). (The return may become invalid after
92 // changing the environment (HOME variable) or using the getpwuid() function).
93 static const char * get_user_home();
95 void set_specified_service_dir(const char *specified_dir)
97 service_dir = specified_dir;
102 service_dir_pathlist &get_paths()
104 return service_dir_paths;