Skip to content

Commit 6adffeb

Browse files
committed
ext/phar: Use zend_result as return value
Also simplify some calls to functions returning zend_result
1 parent ea4e8d5 commit 6adffeb

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

ext/phar/phar.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ void phar_parse_metadata_lazy(const char *buffer, phar_metadata_tracker *tracker
730730
* This is used by phar_open_from_filename to process the manifest, but can be called
731731
* directly.
732732
*/
733-
static int phar_parse_pharfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, zend_long halt_offset, phar_archive_data** pphar, uint32_t compression, char **error) /* {{{ */
733+
static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, zend_long halt_offset, phar_archive_data** pphar, uint32_t compression, char **error) /* {{{ */
734734
{
735735
char b32[4], *buffer, *endbuffer, *savebuf;
736736
phar_archive_data *mydata = NULL;
@@ -1806,7 +1806,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
18061806
* if not, check to see if its dirname() exists (i.e. "/path/to") and is a directory
18071807
* succeed if we are creating the file, otherwise fail.
18081808
*/
1809-
static int phar_analyze_path(const char *fname, const char *ext, size_t ext_len, int for_create) /* {{{ */
1809+
static zend_result phar_analyze_path(const char *fname, const char *ext, size_t ext_len, int for_create) /* {{{ */
18101810
{
18111811
php_stream_statbuf ssb;
18121812
char *realpath;
@@ -1911,7 +1911,7 @@ static int phar_analyze_path(const char *fname, const char *ext, size_t ext_len,
19111911
/* }}} */
19121912

19131913
/* check for ".phar" in extension */
1914-
static int phar_check_str(const char *fname, const char *ext_str, size_t ext_len, int executable, int for_create) /* {{{ */
1914+
static zend_result phar_check_str(const char *fname, const char *ext_str, size_t ext_len, int executable, int for_create) /* {{{ */
19151915
{
19161916
const char *pos;
19171917

@@ -2057,6 +2057,7 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len
20572057
}
20582058
}
20592059

2060+
// TODO Use some sort of loop here instead of a goto
20602061
pos = memchr(filename + 1, '.', filename_len);
20612062
next_extension:
20622063
if (!pos) {
@@ -2078,30 +2079,23 @@ zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len
20782079
*ext_len = strlen(pos);
20792080

20802081
/* file extension must contain "phar" */
2081-
switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create)) {
2082-
case SUCCESS:
2083-
return SUCCESS;
2084-
case FAILURE:
2085-
/* we are at the end of the string, so we fail */
2086-
return FAILURE;
2087-
}
2082+
return phar_check_str(filename, *ext_str, *ext_len, executable, for_create);
20882083
}
20892084

20902085
/* we've found an extension that ends at a directory separator */
20912086
*ext_str = pos;
20922087
*ext_len = slash - pos;
20932088

2094-
switch (phar_check_str(filename, *ext_str, *ext_len, executable, for_create)) {
2095-
case SUCCESS:
2096-
return SUCCESS;
2097-
case FAILURE:
2098-
/* look for more extensions */
2099-
pos = strchr(pos + 1, '.');
2100-
if (pos) {
2101-
*ext_str = NULL;
2102-
*ext_len = 0;
2103-
}
2104-
goto next_extension;
2089+
if (phar_check_str(filename, *ext_str, *ext_len, executable, for_create) == SUCCESS) {
2090+
return SUCCESS;
2091+
}
2092+
2093+
/* look for more extensions */
2094+
pos = strchr(pos + 1, '.');
2095+
if (pos) {
2096+
*ext_str = NULL;
2097+
*ext_len = 0;
2098+
goto next_extension;
21052099
}
21062100

21072101
return FAILURE;

0 commit comments

Comments
 (0)