MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Platform_SetDefaultCurrentDirectory

Function Platform_SetDefaultCurrentDirectory

src/Platform_Posix.c:1650–1680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1648}
1649
1650cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
1651 char path[NATIVE_STR_LEN];
1652 int i, len = 0;
1653 cc_result res;
1654 if (!IsProblematicWorkingDirectory()) return 0;
1655
1656 res = Process_RawGetExePath(path, &len);
1657 if (res) return res;
1658
1659 /* get rid of filename at end of directory */
1660 for (i = len - 1; i >= 0; i--, len--) {
1661 if (path[i] == '/') break;
1662 }
1663
1664 #ifdef CC_BUILD_MACOS
1665 static const cc_string bundle = String_FromConst(".app/Contents/MacOS/");
1666 cc_string raw = String_Init(path, len, 0);
1667
1668 /* If running from within a bundle, set data folder to folder containing bundle */
1669 if (String_CaselessEnds(&raw, &bundle)) {
1670 len -= bundle.length;
1671
1672 for (i = len - 1; i >= 0; i--, len--) {
1673 if (path[i] == '/') break;
1674 }
1675 }
1676 #endif
1677
1678 path[len] = '\0';
1679 return chdir(path) == -1 ? errno : 0;
1680}
1681#endif
1682#endif

Callers

nothing calls this directly

Calls 4

String_InitFunction · 0.85
String_CaselessEndsFunction · 0.85
Process_RawGetExePathFunction · 0.70

Tested by

no test coverage detected