X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=phpstr%2Fphpstr.h;h=51c2b42b8250ae71de5e5e4d5567a9b7856f4695;hp=50d9c283c14616a619ce72ee1cf93131dc4f4a67;hb=81e4342a90700e1762f04e5f5f542d368fcb79c2;hpb=af674f03c32f0f56b7f8c67e61c7e86b3ea23be5 diff --git a/phpstr/phpstr.h b/phpstr/phpstr.h index 50d9c28..51c2b42 100644 --- a/phpstr/phpstr.h +++ b/phpstr/phpstr.h @@ -4,12 +4,18 @@ #ifndef _PHPSTR_H_ #define _PHPSTR_H_ +#include "php.h" + #ifdef PHP_WIN32 # define PHPSTR_API __declspec(dllexport) #else # define PHPSTR_API #endif +#define PHPSTR(p) ((phpstr *) (p)) +#define PHPSTR_VAL(p) (PHPSTR(p))->data +#define PHPSTR_LEN(p) (PHPSTR(p))->used + #define FREE_PHPSTR_PTR(STR) efree(STR) #define FREE_PHPSTR_VAL(STR) phpstr_dtor(STR) #define FREE_PHPSTR_ALL(STR) phpstr_free(STR) @@ -35,21 +41,19 @@ RETVAL_STRINGL((STR)->data, (STR)->used, (dup)); \ FREE_PHPSTR((free), (STR)); -struct _phpstr { +typedef struct { size_t size; char *data; size_t used; size_t free; -}; -typedef struct _phpstr phpstr; +} phpstr; -enum _phpstr_free { +typedef enum { PHPSTR_FREE_NOT = 0, PHPSTR_FREE_PTR, /* efree() */ PHPSTR_FREE_VAL, /* phpstr_dtor() */ PHPSTR_FREE_ALL /* phpstr_free() */ -}; -typedef enum _phpstr_free phpstr_free_t; +} phpstr_free_t; #define PHPSTR_ALL_FREE(STR) PHPSTR_FREE_ALL,(STR) #define PHPSTR_PTR_FREE(STR) PHPSTR_FREE_PTR,(STR) @@ -66,7 +70,7 @@ PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_ #define phpstr_from_zval(z) phpstr_from_string(Z_STRVAL(z), Z_STRLEN(z)) #define phpstr_from_zval_ex(b, z) phpstr_from_string_ex(b, Z_STRVAL(z), Z_STRLEN(z)) #define phpstr_from_string(s, l) phpstr_from_string_ex(NULL, (s), (l)) -PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, char *string, size_t length); +PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length); /* usually only called from within the internal functions */ #define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0) @@ -100,7 +104,7 @@ PHPSTR_API phpstr *phpstr_right(const phpstr *buf, size_t length); PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t len); /* remove a substring */ -PHPSTR_API ssize_t phpstr_cut(phpstr *buf, size_t offset, size_t length); +PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length); /* get a complete phpstr duplicate */ PHPSTR_API phpstr *phpstr_dup(const phpstr *buf);