From: William A. Rowe Jr Date: Thu, 12 Oct 2000 19:45:56 +0000 (+0000) Subject: Modify ap_make_dirstr_prefix, platforms with HAVE_DRIVE_LETTERS or NETWARE X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4531d49ca66b5fa26c605e887bbe6b76ab9111e4;p=apache Modify ap_make_dirstr_prefix, platforms with HAVE_DRIVE_LETTERS or NETWARE can request 0 elements, returning the '/' root. [William Rowe, Tim Costello] from 1.3, with documentation git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86571 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/httpd.h b/include/httpd.h index 9f6fe25e90..3c34bb7ea6 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1323,13 +1323,16 @@ API_EXPORT(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *s); */ API_EXPORT(int) ap_count_dirs(const char *path); /** - * copy at most n leading directories of s into d d should be at least as - * large as s plus 1 extra byte assumes n > 0 + * Copy at most n leading directories of s into d d should be at least as + * large as s plus 1 extra byte * @param d The location to copy to * @param s The location to copy from * @param n The number of directories to copy * @return value is the ever useful pointer to the trailing \0 of d * @deffunc char *ap_make_dirstr_prefix(char *d, const char *s, int n) + * @tip on platforms with drive letters, n = 0 returns the "/" root, + * whereas n = 1 returns the "d:/" root. On all other platforms, n = 0 + * returns the empty string. */ API_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n); /** diff --git a/server/util.c b/server/util.c index 651a0cacec..dcff682a1d 100644 --- a/server/util.c +++ b/server/util.c @@ -529,7 +529,7 @@ API_EXPORT(void) ap_no2slash(char *name) s = d = name; -#ifdef WIN32 +#ifdef HAVE_UNC_PATHS /* Check for UNC names. Leave leading two slashes. */ if (s[0] == '/' && s[1] == '/') *d++ = *s++; @@ -563,6 +563,14 @@ API_EXPORT(void) ap_no2slash(char *name) */ API_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n) { +#if defined(HAVE_DRIVE_LETTERS) || defined(NETWARE) + if (!n) { + *d = '/'; + *++d = '\0'; + return (d); + } +#endif /* def HAVE_DRIVE_LETTERS || NETWARE */ + for (;;) { if (*s == '\0' || (*s == '/' && (--n) == 0)) { *d = '/';