In message <[EMAIL PROTECTED]> Ben Smithurst writes:
:       while (path[strlen(path) - 1] == '/')
:               path[strlen(path) - 1] = 0;
: 
: :-) Preferably '\0' too of course like you say later.

Yes.  Actually, I'd do this like:

        cp = path + strlen(path) - 1;
        while (cp > path && *cp == '/')
                *cp-- = '\0';

Since it doesn't have the buffer overflow the above code does in the
'////' case.  It also gets that case right (if my mental walkthrough
can be truested).  A nice side effect is that it doesn't call strlen N
times making it a O(N) algorythm, rather than an O(N^2) algorythm.
Likely only of secondary importance since most strings don't contain
lots of // in them :-).

Warner


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to