[PHP-DEV] [imp] No data: str_to_str patch for php3.0.6 (fwd) From: php3dev (php3dev <email protected>)
Date: 02/05/99

Zeev .. this may not have gotten to php-dev
        look below for ---->

        o Patch applied on Dec [vmms?] reported solved *no data* problem
which has been problem at IMP last day or so

Action: Look reasonable fix?

Harv
-nnnn-
---------- Forwarded message ----------
Date: Fri, 5 Feb 1999 10:51:48 +0100
From: Mathieu Clabaut <clabault <email protected>>
Reply-To: imp <email protected>
To: liste IMP <imp <email protected>>
Subject: [PHP-DEV] [imp] No data: str_to_str patch for php3.0.6

The following source code of the _php3_str_to_str function seems to be a
working replacement of the original one in php-3.0.6...
No more "No Data" messages since (hope it will last some times ;-))

static char *_php3_str_to_str(char *haystack, int length,
        char *needle, int needle_len, char *str, int str_len, int *_new_length)
{
        char *p, *q;
        char *r, *s;
        char *end = haystack + length;
        char *new, *off;
        
        new = malloc(length);
        /* we jump through haystack searching for the needle. hurray! */
        for(p = haystack, q = new;
                        (r = _php3_memnstr(p, needle, needle_len, end));) {
        /* this ain't optimal. you could call it `efficient memory usage' */
                realloc(new, (q - new) + (r - p) + (str_len) + 1);
                memcpy(q, p, r - p);
                q += r - p;
                memcpy(q, str, str_len);
                q += str_len;
                p = r + needle_len;
        }
        /* if there is a rest, copy it */
        if((end - p)>0) {
                s = (q) + (end - p);
                off = realloc(new, s - new + 1);
                if (off != new) {
                        if(!off){
                                goto finish;
                        }
                        q += off - new;
                        new = off;
------> /* need to recompute s also, since q has been changed */
------> s = (q) + (end - p);
                }
                memcpy(q, p, end - p);
                q = s;
        }
finish:
        *q = '\0';
        if(_new_length) *_new_length = q - new;
        return new;
}

______________________________________________________________________________
Mathieu CLABAUT mailto://clabault <email protected>
DIGINEXT tel: 04 42 97 56 47
Le Tertia II, Pôle d'activite des Milles fax: 04 42 97 56 49
13851 Aix En Provence - cedex 3 e-mail: diginext <email protected>
------------------------------------------------------------------------------
 

--
IMP mailing list: http://web.horde.org
To unsubscribe, e-mail: imp-unsubscribe <email protected>
For additional commands, e-mail: imp-help <email protected>
NNNN

-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>