| 14 | extern char* fake_heap_end; |
| 15 | |
| 16 | void __attribute__((weak)) __system_initArgv(void) |
| 17 | { |
| 18 | int i; |
| 19 | const char* arglist = envGetSystemArgList(); |
| 20 | const char* temp = arglist; |
| 21 | |
| 22 | // Check if the argument list is present |
| 23 | if (!temp) |
| 24 | return; |
| 25 | |
| 26 | // Retrieve argc |
| 27 | __system_argc = *(u32*)temp; |
| 28 | temp += sizeof(u32); |
| 29 | |
| 30 | // Find the end of the argument data |
| 31 | for (i = 0; i < __system_argc; i ++) |
| 32 | { |
| 33 | for (; *temp; temp ++); |
| 34 | temp ++; |
| 35 | } |
| 36 | |
| 37 | // Reserve heap memory for argv data |
| 38 | u32 argSize = temp - arglist - sizeof(u32); |
| 39 | __system_argv = (char**)fake_heap_start; |
| 40 | fake_heap_start += sizeof(char**)*(__system_argc + 1); |
| 41 | char* argCopy = fake_heap_start; |
| 42 | fake_heap_start += argSize; |
| 43 | |
| 44 | // Fill argv array |
| 45 | memcpy(argCopy, &arglist[4], argSize); |
| 46 | temp = argCopy; |
| 47 | for (i = 0; i < __system_argc; i ++) |
| 48 | { |
| 49 | __system_argv[i] = (char*)temp; |
| 50 | for (; *temp; temp ++); |
| 51 | temp ++; |
| 52 | } |
| 53 | |
| 54 | // Grab 3dslink host address if avaliable |
| 55 | if ( __system_argc > 1 && |
| 56 | strlen(__system_argv[__system_argc - 1]) == 17 && |
| 57 | strncmp(&__system_argv[__system_argc - 1][8], "_3DSLINK_", 8) == 0 ) |
| 58 | { |
| 59 | __system_argc--; |
| 60 | __3dslink_host.s_addr = strtoul(__system_argv[__system_argc], NULL, 16); |
| 61 | } |
| 62 | __system_argv[__system_argc] = NULL; |
| 63 | } |
no test coverage detected