Back to index

php5  5.3.10
crc32.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Rasmus Lerdorf <rasmus@php.net>                              |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: crc32.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "basic_functions.h"
00023 #include "crc32.h"
00024 
00025 /* {{{ proto string crc32(string str)
00026    Calculate the crc32 polynomial of a string */
00027 PHP_NAMED_FUNCTION(php_if_crc32)
00028 {
00029        char *p;
00030        int len, nr;
00031        php_uint32 crcinit = 0;
00032        register php_uint32 crc;
00033 
00034        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
00035               return;
00036        }
00037        crc = crcinit^0xFFFFFFFF;
00038 
00039        for (len =+nr; nr--; ++p) {
00040               crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ];
00041        }
00042        RETVAL_LONG(crc^0xFFFFFFFF);
00043 }
00044 /* }}} */
00045 
00046 /*
00047  * Local variables:
00048  * tab-width: 4
00049  * c-basic-offset: 4
00050  * End:
00051  * vim600: sw=4 ts=4 fdm=marker
00052  * vim<600: sw=4 ts=4
00053  */