URL generation glitch fixed
This commit is contained in:
parent
00a95571ed
commit
d37bd5a793
21
src/util.c
21
src/util.c
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user