From: Felipe Pena Date: Sun, 12 Jun 2011 15:15:44 +0000 (+0000) Subject: - Restore basename in filename on non Windows OS X-Git-Tag: php-5.4.0alpha1~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=907fd926e574bab56077a904f1c03a244f97deed;p=php - Restore basename in filename on non Windows OS --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 0417fafffa..34644a553b 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -1146,7 +1146,7 @@ static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *st static char *php_mb_rfc1867_basename(const zend_encoding *encoding, char *filename TSRMLS_DC) /* {{{ */ { - char *s, *tmp; + char *s, *s2, *tmp; const size_t filename_len = strlen(filename); /* The \ check should technically be needed for win32 systems only where @@ -1155,11 +1155,18 @@ static char *php_mb_rfc1867_basename(const zend_encoding *encoding, char *filena * the user does basename() they get a bogus file name. Until IE's user base drops * to nill or problem is fixed this code must remain enabled for all systems. */ s = php_mb_safe_strrchr_ex(filename, '\\', filename_len, (const mbfl_encoding *)encoding); - if ((tmp = php_mb_safe_strrchr_ex(filename, '/', filename_len, (const mbfl_encoding *)encoding)) > s) { - s = tmp; - } - if (s) { - return s + 1; + s2 = php_mb_safe_strrchr_ex(filename, '/', filename_len, (const mbfl_encoding *)encoding); + + if (s && s2) { + if (s > s2) { + return ++s; + } else { + return ++s2; + } + } else if (s) { + return ++s; + } else if (s2) { + return ++s2; } else { return filename; } diff --git a/main/rfc1867.c b/main/rfc1867.c index 4decaec39b..4467aaff16 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -555,17 +555,21 @@ static char *php_ap_getword_conf(const zend_encoding *encoding, char *str TSRMLS static char *php_ap_basename(const zend_encoding *encoding, char *path TSRMLS_DC) { char *s = strrchr(path, '\\'); - if (s) { - char *tmp = strrchr(path, '/'); - if (tmp && tmp > s) { - s = tmp + 1; + char *s2 = strrchr(path, '/'); + + if (s && s2) { + if (s > s2) { + ++s; } else { - s++; + s = ++s2; } - } else { - s = path; + return s; + } else if (s) { + return ++s; + } else if (s2) { + return ++s2; } - return s; + return path; } /*