All pastes #193919 Raw Edit

Mine

public text v1 · immutable
·published 2006-10-07 10:45 UTC
rendered paste body
#include <stdio.h>
#include <string.h>

static inline long int zend_inline_hash_func_php4(char *arKey, int nKeyLength)
{
        long h = 5381;
        char *arEnd = arKey + nKeyLength;
 
        while (arKey < arEnd) {
                h += (h << 5);
                h ^= (long) *arKey++;
        }
        return h;
}



static inline long int zend_inline_hash_func_php5(char *arKey, int nKeyLength)
{
        long h = 5381;
        char *arEnd = arKey + nKeyLength;
 
        while (arKey < arEnd) {
                h += (h << 5);
                h += (long) *arKey++;
        }
        return h;
}

int main(int argc, char *argv[])
{
    if(argc != 3){
            fprintf(stderr, "usage: %s variablename phpversion(4 or 5)\n", argv[0]);
            exit(1);
    }
   
    switch(atoi(argv[2])){
            case 4: fprintf(stdout, "%d\n", zend_inline_hash_func_php4(argv[1], strlen(argv[1])+1)); break;
            case 5: fprintf(stdout, "%d\n", zend_inline_hash_func_php5(argv[1], strlen(argv[1])+1)); break;
    }
}