Hi all, since I started playing around with Zend API, I thought it would be better to start writing some small functions as practice. Then my entire weekend became nightmare.

I've tried to add a function activated in dynamic module, and it gives a very strange result. This function is really simple: taking an integer as argument, returns a 'hhhh:mm:ss' format string. If additional argument (BOOL) is set to true, then the 'hhhh' will turn to 'DD hh'.

Now, it works fine while compiled with GCC alone in standard C style, but while working as a PHP function, the result is like this:

(!靠备h2339:44:05
(!靠备窵▒97D 11:44:05

What are the characters in front of them? Where did they come? It's really confusing......

The original Zend style code is as follow:

--------------------------------------------------------------------

ZEND_FUNCTION(cj_format_clock)
{
        char res[50], myb[10];
        long mys = 0;
        double myd, myh, mym;
        zend_bool useDay = 0;

if ( zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &mys, &useDay) == FAILURE )
        {
php_error(E_ERROR, "Expecting cj_format_clock([(INT)seconds])", get_active_function_name(TSRMLS_C));
                return;
        }

        if ( mys < 0 )
        {
php_error(E_ERROR, "Number of second must be a possitive integer", get_active_function_name(TSRMLS_C));
                return;
        }

        if ( useDay )
        {
                myd = mys / 86400;
                mys %= 86400;
                sprintf(myb, "%.0f", myd);
                strcat(res, myb);
                strcat(res, "D ");
        }

        myh = mys / 3600;
        mys %= 3600;
        if ( myh < 10 )
                strcat(res, "0");
        sprintf(myb, "%.0f", myh);
        strcat(res, myb);

        strcat(res, ":");

        mym = mys / 60;
        mys %= 60;
        if ( mym < 10 )
                strcat(res, "0");
        sprintf(myb, "%.0f", mym);
        strcat(res, myb);

        strcat(res, ":");

        if ( mys < 10 )
                strcat(res, "0");
        sprintf(myb, "%d", mys);
        strcat(res, myb);

        RETURN_STRING(res, 1);
}

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to