Re: new function

From: Date: Sat, 02 Mar 2002 16:19:05 +0000
Subject: Re: new function
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9591@lists.php.net to get a copy of this message
At 05:12 PM 3/2/2002 +0100, Marcus Boerger wrote:
hi guys, what about a new function called strnlen str*n*len which will return the length of a string with a given maximum to avoid problems with strings not zero terminated. size_t strnlen( char* str, size_t maxlen) {
        size_t len = 0;
        if ( str && maxlen && (*str)) {
                do {
                        len++;
                } while ( (--maxlen) && *(++str));
        }
        return len;
} i suggest we put this in a single c file near strlcpy
That doesn't sound right. There aren't supposed to be strings which aren't zero terminated and if there are it should be fixed (or am I missing something?). Andi

« previous php.cvs (#9591) next »