URL generation glitch fixed

This commit is contained in:
Stuart Longland 2008-01-10 12:22:02 +10:00
parent 00a95571ed
commit d37bd5a793

View File

@ -202,20 +202,25 @@ char* get_cgidir() {
/* Obtain the CGI directory URI */
char* get_cgiuri() {
/* We store it here statically for speed */
static char* dir = NULL;
static char* script_filename = NULL;
/* We're given the full path to our CGI binary in the environment
* variables, specifically, the SCRIPT_NAME variable.
* The dirname() of this is our directory.
*/
char* script_filename = getenv("SCRIPT_NAME");
if (script_filename == NULL) return NULL;
if ( dir == NULL ) {
script_filename = getenv("SCRIPT_NAME");
if (script_filename == NULL) return NULL;
char* dir = dirname( script_filename );
dir = dirname( script_filename );
/* We might have a trailing slash, if we do, strip it */
size_t lastchar = strlen( dir ) - 1;
if ( dir[ lastchar ] == '/' )
dir[ lastchar ] = 0;
}
/* Not sure where the pointer from dirname comes from, in some cases
* it's a pointer to within script_filename, others, it's some static
* buffer, so for safe keeping, we'll copy the string out of there and
* free our copy.
*/
char *out = strdup( dir );
return out;
}