1. 字符串 ngx_str_t

源碼路徑 : 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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容