diff options
author | Jani Taskinen <jani@php.net> | 2007-11-05 12:07:37 +0000 |
---|---|---|
committer | Jani Taskinen <jani@php.net> | 2007-11-05 12:07:37 +0000 |
commit | 44c7a7378fd2035b34cac7908737464cb6221431 (patch) | |
tree | 9be7ab45240b2fcc34b19a1c2acbfe10da7ae45f /ext/standard/base64.c | |
parent | 0903022e29b3a8fd8608d9c6ff13915a92ba298f (diff) | |
download | php-git-44c7a7378fd2035b34cac7908737464cb6221431.tar.gz |
MFH
Diffstat (limited to 'ext/standard/base64.c')
-rw-r--r-- | ext/standard/base64.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/ext/standard/base64.c b/ext/standard/base64.c index 16ba1d64e3..c3a1ee16ac 100644 --- a/ext/standard/base64.c +++ b/ext/standard/base64.c @@ -22,14 +22,14 @@ #include "php.h" #include "base64.h" -/* {{{ */ -static const char base64_table[] = - { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' - }; +/* {{{ base64 tables */ +static const char base64_table[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' +}; static const char base64_pad = '='; @@ -53,8 +53,7 @@ static const short base64_reverse_table[256] = { }; /* }}} */ -/* {{{ php_base64_encode */ -PHPAPI unsigned char *php_base64_encode(const unsigned char *str, int length, int *ret_length) +PHPAPI unsigned char *php_base64_encode(const unsigned char *str, int length, int *ret_length) /* {{{ */ { const unsigned char *current = str; unsigned char *p; @@ -135,21 +134,20 @@ void php_base64_init(void) */ /* }}} */ -PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length) +PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length) /* {{{ */ { return php_base64_decode_ex(str, length, ret_length, 0); } +/* }}} */ -/* {{{ php_base64_decode */ -/* as above, but backwards. :) */ -PHPAPI unsigned char *php_base64_decode_ex(const unsigned char *str, int length, int *ret_length, zend_bool strict) +PHPAPI unsigned char *php_base64_decode_ex(const unsigned char *str, int length, int *ret_length, zend_bool strict) /* {{{ */ { const unsigned char *current = str; int ch, i = 0, j = 0, k; /* this sucks for threaded environments */ unsigned char *result; - - result = (unsigned char *)emalloc(length + 1); + + result = (unsigned char *)safe_emalloc(length, 1, 1); /* run through the whole string, converting as we go */ while ((ch = *current++) != '\0' && length-- > 0) { @@ -214,16 +212,15 @@ PHP_FUNCTION(base64_encode) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } - result = php_base64_encode(str, str_len, &ret_length); + result = php_base64_encode((unsigned char*)str, str_len, &ret_length); if (result != NULL) { - RETVAL_STRINGL(result, ret_length, 0); + RETVAL_STRINGL((char*)result, ret_length, 0); } else { RETURN_FALSE; } } /* }}} */ - /* {{{ proto string base64_decode(string str[, bool strict]) Decodes string using MIME base64 algorithm */ PHP_FUNCTION(base64_decode) @@ -236,16 +233,15 @@ PHP_FUNCTION(base64_decode) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &strict) == FAILURE) { return; } - result = php_base64_decode_ex(str, str_len, &ret_length, strict); + result = php_base64_decode_ex((unsigned char*)str, str_len, &ret_length, strict); if (result != NULL) { - RETVAL_STRINGL(result, ret_length, 0); + RETVAL_STRINGL((char*)result, ret_length, 0); } else { RETURN_FALSE; } } /* }}} */ - /* * Local variables: * tab-width: 4 |