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

Method makeFullPathName

Engine/source/platform/platformFileIO.cpp:305–387  ·  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 if(cwd == NULL)
332 cwd = Con::isCurrentScriptToolScript() ? Platform::getMainDotCsDir() : Platform::getCurrentDirectory();
333
334 dStrncpy(buffer, cwd, size);
335 buffer[size-1] = 0;
336
337 const char* defaultDir = Con::getVariable("defaultGame");
338
339 char *ptr = bspath;
340 char *slash = NULL;
341 char *endptr = buffer + dStrlen(buffer) - 1;
342
343 do
344 {
345 slash = dStrchr(ptr, '/');
346 if(slash)
347 {
348 *slash = 0;
349
350 // Directory
351
352 if(dStrcmp(ptr, "..") == 0)
353 {
354 // Parent
355 endptr = dStrrchr(buffer, '/');
356 if (endptr)
357 *endptr-- = 0;
358 }
359 else if(dStrcmp(ptr, ".") == 0)
360 {
361 // Current dir
362 }

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected