SMART STRING API
This article was copied from http://www.akbkhome.com/blog.php/View/111/smart_str_API.html
from:
#include "ext/standard/php_smart_str.h"The Struct:
1 2 3 4 5 | typedef struct { char *c; // data goes here.. size_t len; // the current length size_t a; // the allocated size } smart_str; |
EXAMPLE:
1 2 3 4 5 6 7 8 | smart_str *sstr; sstr = emalloc(sizeof(smart_str)); smart_str_sets(sstr, strdup("")); // start it clean. ..... smart_str_free(sstr); smart_str sstr = {0}; smart_str_alloc(&sstr, 100); smart_str_sets(&sstr, strdup("This is a string")); smart_str_free(&sstr); |

