MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ExpandPath

Function ExpandPath

tensorflow/tools/graph_transforms/transform_graph.cc:135–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135std::string ExpandPath(const std::string& path_string) {
136#if defined(PLATFORM_WINDOWS)
137 return path_string;
138#else
139 if (path_string.empty() || path_string[0] != '~') {
140 return path_string;
141 }
142
143 const char* home = nullptr;
144 std::string::size_type prefix = path_string.find_first_of('/');
145 if (path_string.length() == 1 || prefix == 1) {
146 // The value of $HOME, e.g., ~/foo
147 home = getenv("HOME");
148 if (!home) {
149 // If HOME is not available, get uid
150 struct passwd* pw = getpwuid(getuid());
151 if (pw) {
152 home = pw->pw_dir;
153 }
154 }
155 } else {
156 // The value of ~user, e.g., ~user/foo
157 std::string user(path_string, 1, (prefix == std::string::npos)
158 ? std::string::npos
159 : prefix - 1);
160 struct passwd* pw = getpwnam(user.c_str());
161 if (pw) {
162 home = pw->pw_dir;
163 }
164 }
165
166 if (!home) {
167 return path_string;
168 }
169
170 string path(home);
171 if (prefix == std::string::npos) {
172 return path;
173 }
174
175 if (path.length() == 0 || path[path.length() - 1] != '/') {
176 path += '/';
177 }
178 path += path_string.substr(prefix + 1);
179 return path;
180#endif
181}
182
183int ParseFlagsAndTransformGraph(int argc, char* argv[], bool init_main) {
184 string in_graph_string = "";

Callers 1

Calls 3

c_strMethod · 0.80
emptyMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected