On Sun, 16 Feb 2003, Andi Gutmans wrote:
> At 03:41 PM 2/13/2003 -0500, James E. Flemer wrote:
> >RCS file: /repository/TSRM/tsrm_virtual_cwd.c,v
> >retrieving revision 1.41
> >diff -u -b -r1.41 tsrm_virtual_cwd.c
> >--- TSRM/tsrm_virtual_cwd.c 6 Nov 2002 18:07:22 -0000 1.41
> >+++ TSRM/tsrm_virtual_cwd.c 13 Feb 2003 20:40:07 -0000
> >@@ -303,7 +303,7 @@
> > return (0);
> >
> > #if !defined(TSRM_WIN32) && !defined(NETWARE)
> >- if (IS_ABSOLUTE_PATH(path, path_length)) {
> >+ if (IS_ABSOLUTE_PATH(path, path_length) || (state->cwd_length < 1)) {
> > if (use_realpath && realpath(path, resolved_path)) {
> > path = resolved_path;
> > path_length = strlen(path);
>
> Will realpath() work in cases where getcwd() didn't work? (btw it's nicer
> to check state->cwd_length == 0 than < 1 IMO).
Most realpath() implementations call getcwd(); realpath()
on Solaris seems to, so it fails too.
> >@@ -363,6 +363,7 @@
> > }
> >
> >
> >+ if (state->cwd_length > 0 || IS_ABSOLUTE_PATH(path, path_length)) {
> > ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
> > while (ptr) {
> > ptr_length = strlen(ptr);
> >@@ -416,6 +417,11 @@
> > state->cwd[state->cwd_length+1] = '\0';
> > state->cwd_length++;
> > }
> >+ } else {
> >+ state->cwd = (char *) realloc(state->cwd, path_length+1);
> >+ memcpy(state->cwd, path, path_length+1);
> >+ state->cwd_length = path_length;
> >+ }
>
> I'm trying to think if there's some other way of doing this. What is the
> main problem in this loop? Does it add / or c:\ in the beginning of the
> string?
Yes, that loop adds prefix of "/". Like I said, this
probably is not the cleanest solution, but it was quick and
got 4.3 running for now. I am open to suggestions on
improvement. One thought of mine was to wrap getcwd() so
that when it fails, it would return ".", and then make sure
that nothing *needed* absolute paths. (I believe the
_once() functions will not like this, or may end up
allowing the same file included multiple times w/o the help
of realpath().)
I sort of wonder why PHP does uses getcwd()/realpath() so
much. It is commonly recomended to use open(".") and
fchdir() for a "directory stack". Resolving every single
opened file with realpath() seems a waste. I saw some
discussion on this last month (Subj: Reducing the number of
system calls ...). If the main issue was _once(), would it
be possible to use inodes to prevent multiple inclusion?
(You'd still need a fstat() to get inodes but no realpath()
or getcwd().)
-James
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php