Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Module.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_Module_h_
5#define _Stroika_Foundation_Execution_Module_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <filesystem>
10
11#if qStroika_Foundation_Common_Platform_POSIX
12#include <unistd.h>
13#endif
14
15#include "Stroika/Foundation/Characters/SDKString.h"
16#include "Stroika/Foundation/Common/Common.h"
17#include "Stroika/Foundation/Common/Property.h"
18#include "Stroika/Foundation/Containers/Mapping.h"
19#include "Stroika/Foundation/Containers/Sequence.h"
20#include "Stroika/Foundation/Execution/LazyInitialized.h"
21
22#if !defined(qHas_pid_t)
23#error "qHas_pid_t must be defined in StroikaConfig.h"
24#endif
25
27
28#if qHas_pid_t
29 using pid_t = ::pid_t;
30#else
31#if qStroika_Foundation_Common_Platform_Windows
32 using pid_t = DWORD;
33#else
34 using pid_t = int;
35#endif
36#endif
37
38 /**
39 * The directory where the executable that is running this code is located. If this code is compiled into a DLL,
40 * this returns the executable directory for the underlying process/executable (not the DLL/so file).
41 */
42 filesystem::path GetEXEDir ();
43
44 /**
45 * The path where the executable that is running this code is located. If this code is compiled into a DLL,
46 * this returns the executable for the underlying process/executable (not the DLL/so file).
47 */
48 filesystem::path GetEXEPath ();
49
50 /**
51 * Return the full path to the given process (throws if not found).
52 *
53 * NYI for WINDOWS.
54 */
55 filesystem::path GetEXEPath (pid_t processID);
56
57 /**
58 * The set of system locations to look for an executable (note order matters, which is why this is a Sequence)
59 */
61
62#if qStroika_Foundation_Common_Platform_Windows
63 /**
64 * The set of system extensions to try for a given file to see if its an executable (note order matters, which is why this is a Sequence)
65 *
66 * https://wiki.tcl-lang.org/page/PATHEXT
67 */
69#endif
70
71 /**
72 * \brief convert getenv() to a Mapping of SDKString (in case some issue with charactor set conversion)
73 *
74 * \note LazyInitialized so if not used, nearly zero cost
75 */
77
78 /**
79 * \brief convert getenv() to a Mapping of Strings for easier access
80 *
81 * \note LazyInitialized so if not used, nearly zero cost
82 */
84
85 /**
86 * \brief If fn refers to an executable - return it (using kPATH, and kPathEXT as appropriate)
87 *
88 * If fn is an absolute path, use that (possibly with suffixes appended).
89 * If fn is not absolute, try appending it to each path from kPATH, and redo
90 * same check.
91 *
92 * On Windows, if ext is missing, also check kPathEXT
93 *
94 * If no matches, return nullopt.
95 */
96 optional<filesystem::path> FindExecutableInPath (const filesystem::path& fn);
97
98}
99
100/*
101 ********************************************************************************
102 ***************************** Implementation Details ***************************
103 ********************************************************************************
104 */
105
106#endif /*_Stroika_Foundation_Execution_Module_h_*/
value-object, where the value construction is delayed until first needed (can be handy to avoid c++ i...
const LazyInitialized< Containers::Mapping< Characters::String, Characters::String > > kEnvironment
convert getenv() to a Mapping of Strings for easier access
Definition Module.cpp:232
const LazyInitialized< Containers::Sequence< filesystem::path > > kPath
Definition Module.cpp:144
const LazyInitialized< Containers::Mapping< Characters::SDKString, Characters::SDKString > > kRawEnvironment
convert getenv() to a Mapping of SDKString (in case some issue with charactor set conversion)
Definition Module.cpp:180
filesystem::path GetEXEDir()
Definition Module.cpp:43
optional< filesystem::path > FindExecutableInPath(const filesystem::path &fn)
If fn refers to an executable - return it (using kPATH, and kPathEXT as appropriate)
Definition Module.cpp:245
int pid_t
TODO - maybe move this to configuraiotn module???
Definition Module.h:34
filesystem::path GetEXEPath()
Definition Module.cpp:53