Is this a "safe" way to get the current path?
Posted: Sat Feb 10, 2007 8:47 pm
I have been working on getting a platform independent way to get the current path
right now to get the path of what was called I do this:
basically what that does is scan the argv[0] from it's end until it finds a / or \, and upon finding that it adds a \0 to it to null terminate it and then copies it to my open86_dir pre-allocated string
now, is this a safe way to obtain the path? in some OS's will it fail?(it works in windows, and haven't tested it anywhere else)
right now to get the path of what was called I do this:
Code: Select all
void GetOpen86Dir(char *arg){ //arg is argv[0]
char *end=arg+strlen(arg);
while(arg<end){
if(*end=='/' || *end=='\\'){
end++; //save the '/'
*end='\0';
strcpy(open86_dir,arg);
return;
}
end--;
}
strcpy(open86_dir,"");
printf("Warning!! Cannot figure out open86's directory--so using \'./\'");
}
}
now, is this a safe way to obtain the path? in some OS's will it fail?(it works in windows, and haven't tested it anywhere else)