[PHP4BETA] CVS update: php4/ext/standard
| From: | sas | Date: | Sun, 16 May 1999 11:12:23 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/standard | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-876@lists.php.net to get a copy of this message | ||
Date: Sunday May 16, 1999 @ 7:12
Author: sas
Update of /repository/php4/ext/standard
In directory php:/tmp/cvs-serv15068
Modified Files:
php3_string.h string.c
Log Message:
add fast bin2hex string function
Index: php4/ext/standard/php3_string.h
diff -u php4/ext/standard/php3_string.h:1.2 php4/ext/standard/php3_string.h:1.3
--- php4/ext/standard/php3_string.h:1.2 Wed Apr 21 13:57:40 1999
+++ php4/ext/standard/php3_string.h Sun May 16 07:12:23 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: php3_string.h,v 1.2 1999/04/21 17:57:40 sas Exp $ */
+/* $Id: php3_string.h,v 1.3 1999/05/16 11:12:23 sas Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
@@ -79,6 +79,7 @@
extern void php3_stristr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chunk_split(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_parsestr(INTERNAL_FUNCTION_PARAMETERS);
+PHP_FUNCTION(bin2hex);
extern PHPAPI char *_php3_strtoupper(char *s);
extern PHPAPI char *_php3_strtolower(char *s);
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.12 php4/ext/standard/string.c:1.13
--- php4/ext/standard/string.c:1.12 Wed May 12 11:40:15 1999
+++ php4/ext/standard/string.c Sun May 16 07:12:23 1999
@@ -30,7 +30,7 @@
*/
-/* $Id: string.c,v 1.12 1999/05/12 15:40:15 sas Exp $ */
+/* $Id: string.c,v 1.13 1999/05/16 11:12:23 sas Exp $ */
#include <stdio.h>
#include "php.h"
@@ -43,6 +43,50 @@
#include "zend_execute.h"
#include "php_globals.h"
+static char hexconvtab[] = "0123456789abcdef";
+
+static char *php_bin2hex(const char *old, const size_t oldlen, size_t *newlen)
+{
+ char *new = NULL;
+ int i, j;
+
+ new = (char *) emalloc(oldlen * 2 * sizeof(char));
+ if(!new) {
+ return new;
+ }
+
+ for(i = j = 0; i < oldlen; i++) {
+ new[j++] = hexconvtab[old[i] >> 4];
+ new[j++] = hexconvtab[old[i] & 15];
+ }
+
+ if(newlen) *newlen = oldlen * 2 * sizeof(char);
+
+ return new;
+}
+
+/* proto bin2hex(string data)
+ converts the binary representation of data to hex */
+PHP_FUNCTION(bin2hex)
+{
+ pval *data;
+ char *new;
+ size_t newlen;
+
+ if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &data) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string(data);
+
+ new = php_bin2hex(data->value.str.val, data->value.str.len, &newlen);
+
+ if(!new) {
+ RETURN_FALSE;
+ }
+
+ RETURN_STRINGL(new, newlen, 0);
+}
/* {{{ proto int strlen(string str)
Get string length */
--
PHP 4 Beta