33// utilities for JFE to load JE, initiallize, and run profile sentence
44// JFEs are jconsole, jwdw, and jwdp
55// TODO: Remove all void* where applicable when other parts of the code start being refactored
6+ #include < filesystem>
67#include < string>
78#include < stdexcept>
89#include < cstdint>
@@ -30,8 +31,8 @@ static JgaType jga;
3031static JGetLocaleType jgetlocale;
3132static JGetAType jgeta;
3233static JSetAType jseta;
33- std::string path;
34- std::string pathdll;
34+ std::filesystem::path path;
35+ std::filesystem::path pathdll;
3536
3637auto
3738jedo (char const * sentence) -> int {
@@ -101,7 +102,6 @@ jepath(char* arg, char* lib) -> void {
101102 // C strings need to be used for POSIX APIs and macOS APIs
102103 auto arg2 = new char [sz];
103104 auto arg3 = new char [sz];
104- auto path_temp = new char [sz];
105105 // Return for readlinks
106106 int n;
107107
@@ -127,44 +127,19 @@ jepath(char* arg, char* lib) -> void {
127127 arg3[n] = 0 ;
128128
129129 if (' /' == *arg3)
130- strcpy (path_temp, arg3);
131- else {
132- if (!getcwd (path_temp, sizeof (path_temp))) path_temp[0 ] = 0 ;
133- strcat (path_temp, " /" );
134- strcat (path_temp, arg3);
135- }
130+ path = arg3;
131+ else
132+ path = std::filesystem::current_path () / arg3;
136133 // Now append path_temp to path, as all POSIX and macOS API calls are done, and free up arg2, arg3, path_temp.
137- path.append (path_temp);
138- delete[] path_temp;
139134 delete[] arg2;
140135 delete[] arg3;
141136
142- // Remove everything after the last / as that would be the current executables name
143- path.erase (std::next (path.begin (), path.rfind (' /' )), path.end ());
137+ path.remove_filename ();
144138
145139 // remove ./ and backoff ../
146- util::remove_all_occurrences (path, " ../" );
147- util::remove_all_occurrences (path, " ./" );
148-
149- pathdll.append (path);
150- pathdll.append (" /" );
151- pathdll.append (JDLLNAME);
152-
153- if (*lib) {
154- if (' /' != *lib) {
155- pathdll.append (path);
156- pathdll.append (" /" );
157- }
158- pathdll.append (lib);
159- }
160- }
140+ path = path.lexically_normal ();
161141
162- // called by jwdp (java jnative.c) to set path
163- auto
164- jesetpath (char * arg) -> void {
165- pathdll.append (arg);
166- path.append (arg);
167- path.erase (std::next (path.begin (), path.rfind (' /' )), path.end ());
142+ pathdll = path / (*lib ? lib : JDLLNAME);
168143}
169144
170145// build and run first sentence to set BINPATH, ARGV, and run profile
0 commit comments