MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / makeFullPathName

Method makeFullPathName

Engine/source/platform/platformFileIO.cpp:305–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305char * Platform::makeFullPathName(const char *path, char *buffer, U32 size, const char *cwd /* = NULL */)
306{
307 char bspath[1024];
308 dStrncpy(bspath, path, sizeof(bspath));
309 bspath[sizeof(bspath)-1] = 0;
310
311 for(S32 i = 0;i < dStrlen(bspath);++i)
312 {
313 if(bspath[i] == '\\')
314 bspath[i] = '/';
315 }
316
317 if(Platform::isFullPath(bspath))
318 {
319 // Already a full path
320 #if defined(TORQUE_OS_WIN)
321 _resolveLeadingSlash(bspath, sizeof(bspath));
322 #endif
323 dStrncpy(buffer, bspath, size);
324 buffer[size-1] = 0;
325 return buffer;
326 }
327
328 // [rene, 05/05/2008] Based on overall file handling in Torque, it does not seem to make
329 // that much sense to me to base things off the current working directory here.
330
331 #ifndef TORQUE_SCECURE_VFS
332 if(cwd == NULL)
333 cwd = Con::isCurrentScriptToolScript() ? Platform::getMainDotCsDir() : Platform::getCurrentDirectory();
334 #else
335 if (cwd == NULL)
336 cwd = "game:/";
337 #endif
338
339 dStrncpy(buffer, cwd, size);
340 buffer[size-1] = 0;
341
342 const char* defaultDir = Con::getVariable("defaultGame");
343
344 char *ptr = bspath;
345 char *slash = NULL;
346 char *endptr = buffer + dStrlen(buffer) - 1;
347
348 do
349 {
350 slash = dStrchr(ptr, '/');
351 if(slash)
352 {
353 *slash = 0;
354
355 // Directory
356
357 if(String::compare(ptr, "..") == 0)
358 {
359 // Parent
360 endptr = dStrrchr(buffer, '/');
361 if (endptr)
362 *endptr-- = 0;

Callers

nothing calls this directly

Calls 9

dStrncpyFunction · 0.85
_resolveLeadingSlashFunction · 0.85
getVariableFunction · 0.85
compareFunction · 0.85
catPathFunction · 0.85
dStrlenFunction · 0.50
dStrchrFunction · 0.50
dStrrchrFunction · 0.50

Tested by

no test coverage detected