cvs: /php4 php_virtual_cwd.c

From: Date: Sat, 25 Mar 2000 16:28:47 +0000
Subject: cvs: /php4 php_virtual_cwd.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-12600@lists.php.net to get a copy of this message
andi Sat Mar 25 08:28:47 2000 EDT Modified files: /php4 php_virtual_cwd.c Log: - Support getcwd() semantics. - We need to change this whole business to work with ZTS globals Index: php4/php_virtual_cwd.c diff -u php4/php_virtual_cwd.c:1.13 php4/php_virtual_cwd.c:1.14 --- php4/php_virtual_cwd.c:1.13 Sun Mar 19 13:10:48 2000 +++ php4/php_virtual_cwd.c Sat Mar 25 08:28:16 2000 @@ -108,7 +108,7 @@ } -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 @@ 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 @@ 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("...")

« previous php.version4 (#12600) next »