cvs: /php4 php_virtual_cwd.c
| From: | Andi Gutmans | Date: | Sun, 02 Apr 2000 19:28:55 +0000 |
| Subject: | cvs: /php4 php_virtual_cwd.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-13015@lists.php.net to get a copy of this message | ||
andi Sun Apr 2 12:28:55 2000 EDT
Modified files:
/php4 php_virtual_cwd.c
Log:
- A bit more cleanups.
- Need to implement virtual_chdir_file() to replace chdir_file() in
sapi/apache so that we can start testing apache and debug it.
Index: php4/php_virtual_cwd.c
diff -u php4/php_virtual_cwd.c:1.21 php4/php_virtual_cwd.c:1.22
--- php4/php_virtual_cwd.c:1.21 Sun Apr 2 12:04:59 2000
+++ php4/php_virtual_cwd.c Sun Apr 2 12:28:25 2000
@@ -15,7 +15,7 @@
ZEND_DECLARE_MODULE_GLOBALS(cwd);
-cwd_state true_global_cwd_state;
+cwd_state main_cwd_state; /* True global */
#ifndef ZEND_WIN32
#include <unistd.h>
@@ -88,6 +88,15 @@
#ifndef IS_DIR_OK
#define IS_DIR_OK(state) (php_is_dir_ok(state) == 0)
#endif
+
+
+#define CWD_STATE_COPY(d, s) \
+ (d)->cwd_length = (s)->cwd_length; \
+ (d)->cwd = (char *) malloc((s)->cwd_length+1); \
+ memcpy((d)->cwd, (s)->cwd, (s)->cwd_length+1);
+
+#define CWD_STATE_FREE(s) \
+ free((s)->cwd);
static int php_is_dir_ok(const cwd_state *state)
{
@@ -111,9 +120,7 @@
static void cwd_globals_ctor(zend_cwd_globals *cwd_globals)
{
- cwd_globals->cwd.cwd = (char *) malloc(true_global_cwd_state.cwd_length+1);
- memcpy(cwd_globals->cwd.cwd, true_global_cwd_state.cwd, true_global_cwd_state.cwd_length+1);
- cwd_globals->cwd.cwd_length = true_global_cwd_state.cwd_length;
+ CWD_STATE_COPY(&cwd_globals->cwd, &main_cwd_state);
}
void virtual_cwd_startup()
@@ -125,8 +132,8 @@
if (!result) {
cwd[0] = '\0';
}
- true_global_cwd_state.cwd = strdup(cwd);
- true_global_cwd_state.cwd_length = strlen(cwd);
+ main_cwd_state.cwd = strdup(cwd);
+ main_cwd_state.cwd_length = strlen(cwd);
ZEND_INIT_MODULE_GLOBALS(cwd, cwd_globals_ctor, NULL);
}
@@ -202,9 +209,8 @@
if (path_length == 0)
return (0);
- old_state = (cwd_state *) malloc(sizeof(*old_state));
- old_state->cwd = strdup(state->cwd);
- old_state->cwd_length = state->cwd_length;
+ old_state = (cwd_state *) malloc(sizeof(cwd_state));
+ CWD_STATE_COPY(old_state, state);
if (IS_ABSOLUTE_PATH(path, path_length)) {
copy_amount = COPY_WHEN_ABSOLUTE;
@@ -259,13 +265,13 @@
}
if (verify_path && verify_path(state)) {
- free(state->cwd);
+ CWD_STATE_FREE(state);
*state = *old_state;
ret = 1;
} else {
- free(old_state->cwd);
+ CWD_STATE_FREE(old_state);
}
free(old_state);
@@ -286,8 +292,7 @@
int retval;
CWDLS_FETCH();
- new_state = CWDG(cwd);
- new_state.cwd = strdup(CWDG(cwd).cwd);
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
retval = virtual_file_ex(&new_state, path, php_is_file_ok);
*filepath = new_state.cwd;
@@ -301,8 +306,7 @@
int retval;
CWDLS_FETCH();
- new_state = CWDG(cwd);
- new_state.cwd = strdup(CWDG(cwd).cwd);
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
retval = virtual_file_ex(&new_state, path, php_is_file_ok);
@@ -310,7 +314,7 @@
return NULL;
}
f = fopen(new_state.cwd, mode);
- free(new_state.cwd);
+ CWD_STATE_FREE(&new_state);
return f;
}