Re: Problems with directory length
- Posted by MrAl Sep 17, 2009
- 1488 views
Hello again,
Ok, it worked
I used Derek's solution of modifying the runtime file that handled the command line. Now i guess the question 'begged' is, just how many bytes need to be allocated in order to satisfy the most demanding user/system? I used 600 bytes just to test it out, but im thinking maybe 2048 or a little more, like 2050, but maybe even 4096 plus two so say 4100 to make it even, to handle unicode chars too (but i havent actually looked into this yet).
Any other ideas?
So you didn't use my solution then And I assume you are patching the version 3 Euphoria.
My solution enables it to use any length at all. I didn't code a fixed length. Instead, I start at 64 bytes, and continue the get the exe's path until I get all of it, adding 32 bytes at a time to the buffer area.
Here is my code ...
int ns; int bs; // don't use EMalloc yet: argv = (char **)malloc((strlen(cmdline)/2+3) * sizeof(char *)); #ifdef EWINDOWS if (*argc == 1) { argv[0] = 0; bs = 32; ns = bs; /* If ns equals bs it means that we have not gotten the complete path string yet */ while (ns == bs) { bs += 32; if (argv[0] != 0) free((void *)argv[0]); argv[0] = (char *)malloc(bs + 2); ns = GetModuleFileName(NULL, (LPTSTR)argv[0], bs); } if (ns == 0) argv[0] = "eui.exe"; w = 1; } else #endif
which replaced this ...
// don't use EMalloc yet: argv = (char **)malloc((strlen(cmdline)/2+3) * sizeof(char *)); #ifdef EWINDOWS if (*argc == 1) { argv[0] = malloc(130); if (GetModuleFileName(NULL, (LPTSTR)argv[0], 128) == 0) argv[0] = "EXW.EXE"; w = 1; } else #endif
Hello again,
Oh ok, so i didnt use your solution exactly (i didnt actually see it until now), so i improvised a little
I like your solution better actually, with a tiny modification...
I think i would make the increment a little larger (i am not afraid to use a little more mem here) so i would start by using malloc with say 128 bytes and then in the loop use realloc instead so i dont have a bunch of lost pointers with associated lost memory. I like the idea though of allocating on the fly so that we can always be sure that we are going to satisfy the demands of the system/user. I think i should implement this change too. Oh yeah, it was with 3.11, at least for now.