1. 字符串 ngx_str_t

2017-11-17  本文已影响0人  IN4

源码路径 : 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

结果

t.len = 9
t.data = hello ngx
上一篇 下一篇

猜你喜欢

热点阅读