]> granicus.if.org Git - php/commitdiff
- Support getcwd() semantics.
authorAndi Gutmans <andi@php.net>
Sat, 25 Mar 2000 16:28:16 +0000 (16:28 +0000)
committerAndi Gutmans <andi@php.net>
Sat, 25 Mar 2000 16:28:16 +0000 (16:28 +0000)
- We need to change this whole business to work with ZTS globals

main/php_virtual_cwd.c

index a4583fdca1cee5bad051d5cefb9d13c4f1872e27..44181205c6efeffab9084d7cd87473456bda0cd1 100644 (file)
@@ -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("...")