源碼路徑 : src/core/ngx_string.h
typedef struct {
size_t len; //字符串的實際長度
u_char *data; //字符串的值,不包含 c 字符串末尾的 \0
} ngx_str_t;
實例
#include <stdio.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_string.h>
int
main(int argc, char *argv[])
{
ngx_str_t t;
char *str = "hello ngx";
t.len = sizeof(str) - 1;
t.data = (u_char *)str;
printf("t.len = %lu\n", t.len);
printf("t.data = %s\n", t.data);
return 0;
}
運行
gcc ./j_str.c
-I ../../objs/
-I ../core/
-I ../os/unix/
-I /usr/local/opt/pcre/include
-o ./j_str
(說明:pcre路徑為本機pcre具體路徑)
./j_str
結(jié)果
t.len = 9
t.data = hello ngx