On Wed, Mar 4, 2009 at 17:28, Bert Huijben <rhuijben_at_sharpsvn.net> wrote:
>...
> +++ trunk/subversion/libsvn_subr/dirent_uri.c  Wed Mar  4 08:28:30 2009     (r36310)
> @@ -140,6 +140,44 @@ canonicalize_to_upper(char c)
> Â }
> Â #endif
>
> +/* Calculates the length of the dirent absolute or non absolute root in
> +  DIRENT, return 0 if dirent is not rooted  */
> +static apr_size_t
> +dirent_root_length(const char *dirent, apr_size_t len)
> +{
> +#if defined(WIN32) || defined(__CYGWIN__)
> + Â if (len >= 2 && dirent[1] == ':' &&
> + Â Â Â ((dirent[0] >= 'A' && dirent[0] <= 'Z') ||
> + Â Â Â (dirent[0] >= 'a' && dirent[0] <= 'z')))
check dirent[1] after the letter check, and you won't have to test the length.
> + Â Â {
> + Â Â Â return (len > 2 && dirent[2] == '/') ? 3 : 2;
no need to test the length. dirent[2] will be '/' or '\0'.
> + Â Â }
> +
> + Â if (len > 2 && dirent[0] == '/' && dirent[1] == '/')
No need to test the length. The checks will stop if dirent[x] == '\0'
>...
> + Â if (len >= 1 && dirent[0] == '/')
> + Â Â return 1;
> +
> + Â return 0;
dirent[0] will be '/' or '\0' (or somethign else). no need to check
the length. so:
return dirent[0] == '/';
>...
> @@ -760,6 +824,34 @@ char *svn_dirent_join(const char *base,
> Â if (SVN_PATH_IS_EMPTY(component))
> Â Â return apr_pmemdup(pool, base, blen + 1);
>
> +#if defined(WIN32) || defined(__CYGWIN__)
> + Â if (component[0] == '/')
> + Â Â {
> + Â Â Â /* '/' is drive relative on Windows, not absolute like on Posix */
> + Â Â Â if (dirent_is_rooted(base))
> + Â Â Â Â {
> + Â Â Â Â Â /* Join component without '/' to root-of(base) */
> + Â Â Â Â Â blen = dirent_root_length(base, blen);
> + Â Â Â Â Â component++;
> + Â Â Â Â Â clen--;
> +
> + Â Â Â Â Â if (blen == 2 && base[1] == ':') /* "C:" case */
> + Â Â Â Â Â Â {
> + Â Â Â Â Â Â Â char *root = apr_pmemdup(pool, base, 3);
> + Â Â Â Â Â Â Â root[2] = '/'; /* We don't need the final '\0' */
> +
> + Â Â Â Â Â Â Â base = root;
> + Â Â Â Â Â Â Â blen = 3;
I would suggest a local variable at the outer block:
char newbase[3] = "a:/";
dunno if that compiles. worst case:
char newbase[] = { 'a', ':', '/' };
and the above code can be:
if (blen == 2 ...)
{
newbase[0] = base[0];
base = newbase;
blen = 3;
}
> + Â Â Â Â Â Â }
> +
> + Â Â Â Â Â if (clen == 0)
> + Â Â Â Â Â Â return apr_pstrndup(pool, base, blen);
apr_pstrmemdup(pool, base, blen) is better. it won't look for NUL characters.
>...
Cheers,
-g
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1273174
Received on 2009-03-05 19:30:17 CET