diff options
| author | Andi Gutmans <andi@php.net> | 2000-03-25 16:28:16 +0000 |
|---|---|---|
| committer | Andi Gutmans <andi@php.net> | 2000-03-25 16:28:16 +0000 |
| commit | 18e1e63e78c4d18a532c917cf709b8a02af92782 (patch) | |
| tree | ae0352f47681db133f5078dfdab8ff1090bc8d8c | |
| parent | 6a7bc777caf15a0c1952b7c9ee3d43041c6d7ec6 (diff) | |
| download | php-git-18e1e63e78c4d18a532c917cf709b8a02af92782.tar.gz | |
- Support getcwd() semantics.
- We need to change this whole business to work with ZTS globals
| -rw-r--r-- | main/php_virtual_cwd.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index a4583fdca1..44181205c6 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -108,7 +108,7 @@ static int php_is_file_ok(const cwd_state *state) } -char *virtual_getcwd(cwd_state *state, uint *length) +char *virtual_getcwd_ex(cwd_state *state, uint *length) { if (state->cwd_length == 0) { char *retval; @@ -137,6 +137,30 @@ char *virtual_getcwd(cwd_state *state, uint *length) return strdup(state->cwd); } + +/* Same semantics as UNIX getcwd() */ +char *virtual_getcwd(char *buf, size_t size) +{ + cwd_state state; /* Needs to be a ZTS var such as PG(), just included it so that this will compile */ + uint length; + char *cwd; + + cwd = virtual_getcwd_ex(&state, &length); + + if (buf == NULL) { + return cwd; + } + if (length > size-1) { + free(cwd); + errno = ERANGE; /* Is this OK? */ + return NULL; + } + memcpy(buf, cwd, length+1); + free(cwd); + return buf; +} + + /* returns 0 for ok, 1 for error */ int virtual_file_ex(cwd_state *state, char *path, verify_path_func verify_path) { @@ -273,9 +297,9 @@ main(void) state.cwd_length = strlen(state.cwd); #define T(a) \ - printf("[%s] $ cd %s\n", virtual_getcwd(&state, &length), a); \ + printf("[%s] $ cd %s\n", virtual_getcwd_ex(&state, &length), a); \ virtual_chdir(&state, strdup(a)); \ - printf("new path is %s\n", virtual_getcwd(&state, &length)); + printf("new path is %s\n", virtual_getcwd_ex(&state, &length)); T("..") T("...") |
