Here it is (marked line 299 with "<------------")

/* Resolve path relatively to state and put the real path into state */
/* returns 0 for ok, 1 for error */
CWD_API int virtual_file_ex(cwd_state *state, const char *path,
verify_path_func verify_path)
{
         int path_length = strlen(path);
         char *ptr, *path_copy;
         char *tok = NULL;
         int ptr_length;
         cwd_state *old_state;
         int ret = 0;
         int copy_amount = -1;
         char *free_path;
         unsigned char is_absolute = 0;
#ifndef TSRM_WIN32
         char resolved_path[MAXPATHLEN];
#endif

         if (path_length == 0)
                 return (0);

#if !defined(TSRM_WIN32) && !defined(__BEOS__)
         if (IS_ABSOLUTE_PATH(path, path_length)) {
                 if (realpath(path, resolved_path)) {
                         path = resolved_path;
                         path_length = strlen(path);
                 }
         } else { /* Concat current directory with relative path and then
run realpath() on it */
                 char *tmp;
                 char *ptr;

                 ptr = tmp = (char *)
malloc(state->cwd_length+path_length+sizeof("/"));
                 if (!tmp) {
                         return 1;
                 }
                 memcpy(ptr, state->cwd, state->cwd_length);
                 ptr += state->cwd_length;
                 *ptr++ = DEFAULT_SLASH;
                 memcpy(ptr, path, path_length);
                 ptr += path_length;
                 *ptr = '\0';
                 if (realpath(tmp, resolved_path)) { // <------------
                         path = resolved_path;
                         path_length = strlen(path);
                 }
                 free(tmp);
         }
#endif
         free_path = path_copy = tsrm_strndup(path, path_length);

         old_state = (cwd_state *) malloc(sizeof(cwd_state));
         CWD_STATE_COPY(old_state, state);
#if VIRTUAL_CWD_DEBUG
         fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
#endif
         if (IS_ABSOLUTE_PATH(path_copy, path_length)) {
                 copy_amount = COPY_WHEN_ABSOLUTE;
                 is_absolute = 1;
#ifdef TSRM_WIN32
         } else if (IS_UNC_PATH(path_copy, path_length)) {
                 copy_amount = 1;
                 is_absolute = 1;
         } else if (IS_SLASH(path_copy[0])) {
                 copy_amount = 2;
#endif
         }

         if (copy_amount != -1) {
                 state->cwd = (char *) realloc(state->cwd, copy_amount + 1);
                 if (copy_amount) {
                         if (is_absolute) {
                                 memcpy(state->cwd, path_copy, copy_amount);
                                 path_copy += copy_amount;
                         } else {
                                 memcpy(state->cwd, old_state->cwd,
copy_amount);
                         }
                 }
                 state->cwd[copy_amount] = '\0';
                 state->cwd_length = copy_amount;
         }


         ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
         while (ptr) {
                 ptr_length = strlen(ptr);

                 if (IS_DIRECTORY_UP(ptr, ptr_length)) {
                         char save;

                         save = DEFAULT_SLASH;

#define PREVIOUS state->cwd[state->cwd_length - 1]

                         while (IS_ABSOLUTE_PATH(state->cwd,
state->cwd_length) &&
                                         !IS_SLASH(PREVIOUS)) {
                                 save = PREVIOUS;
                                 PREVIOUS = '\0';
                                 state->cwd_length--;
                         }

                         if (!IS_ABSOLUTE_PATH(state->cwd,
state->cwd_length)) {
                                 state->cwd[state->cwd_length++] = save;
                                 state->cwd[state->cwd_length] = '\0';
                         } else {
                                 PREVIOUS = '\0';
                                 state->cwd_length--;
                         }
                 } else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
                         state->cwd = (char *) realloc(state->cwd,
state->cwd_length+ptr_length+1+1);
#ifdef TSRM_WIN32
                         /* Windows 9x will consider C:\\Foo as a network
path. Avoid it. */
                         if (state->cwd[state->cwd_length-1]!=DEFAULT_SLASH) {
                                 state->cwd[state->cwd_length++] =
DEFAULT_SLASH;
                         }
#else
                         state->cwd[state->cwd_length++] = DEFAULT_SLASH;
#endif
                         memcpy(&state->cwd[state->cwd_length], ptr,
ptr_length+1);
                         state->cwd_length += ptr_length;
                 }
                 ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
         }

         if (state->cwd_length == COPY_WHEN_ABSOLUTE) {
                 state->cwd = (char *) realloc(state->cwd,
state->cwd_length+1+1);
                 state->cwd[state->cwd_length] = DEFAULT_SLASH;
                 state->cwd[state->cwd_length+1] = '\0';
                 state->cwd_length++;
         }

         if (verify_path && verify_path(state)) {
                 CWD_STATE_FREE(state);

                 *state = *old_state;

                 ret = 1;
         } else {
                 CWD_STATE_FREE(old_state);
                 ret = 0;
         }

         free(old_state);

         free(free_path);
#if VIRTUAL_CWD_DEBUG
         fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd);
#endif
         return (ret);
}


At 04:18 PM 11/27/2001 -0500, you wrote:
>Okay.  Could you provide the source for the entire virtual_file_ex()
>function from tsrm_virtual_cwd.c file?
>
>-- Dossy
>
>On 2001.11.27, Sean Redmond <[EMAIL PROTECTED]> wrote:
> > (gdb) up
> > #1  0x40291659 in virtual_file_ex (state=0x403ac164,
> >     path=0x833a694 "../src/load_prefs.php", verify_path=0)
> >     at tsrm_virtual_cwd.c:299
> > 299                     if (realpath(tmp, resolved_path)) {
> > (gdb) list
> > 294                     ptr += state->cwd_length;
> > 295                     *ptr++ = DEFAULT_SLASH;
> > 296                     memcpy(ptr, path, path_length);
> > 297                     ptr += path_length;
> > 298                     *ptr = '\0';
> > 299                     if (realpath(tmp, resolved_path)) {
> > 300                             path = resolved_path;
> > 301                             path_length = strlen(path);
> > 302                     }
> > 303                     free(tmp);

Sean Redmond
Brooklyn Museum of Art

Reply via email to