基本資料結構

來源:互聯網
上載者:User
首先,是整數類型:
src/core/ngx_config.h

typedef intptr_t        ngx_int_t;typedef uintptr_t       ngx_uint_t;typedef intptr_t        ngx_flag_t;

即整數、不帶正負號的整數和bool。intptr_t 等三種類型定義如下:
/usr/local/include/stdint.h

/* Types for `void *' pointers.  */#if __WORDSIZE == 64# ifndef __intptr_t_definedtypedef longint        intptr_t;#  define __intptr_t_defined# endiftypedef unsigned longint   uintptr_t;#else# ifndef __intptr_t_definedtypedef int         intptr_t;#  define __intptr_t_defined# endiftypedef unsigned int        uintptr_t;#endif

即:64系統則使用長整形(8位元組),否則使用整形(4位元組)。

然後是字串型:
/src/core/ngx_string.h

typedef struct {    size_t      len;    u_char     *data;} ngx_str_t;

接著,定義了一堆字串相關的函數,類似於對應於ngx_str_t的成員函數吧。

函數 描述
ngx_string(str) 建構函式,str指向\0結尾的字串
ngx_null_string 空建構函式
ngx_str_set(str, text) text指向\0結尾的字串,將它set給ngx_str_t對象str
ngx_strncmp 封裝strncmp
ngx_strcmp 封裝strcmp
… …

此外,順便定義了其他幾個類型:

typedefstruct {    ngx_str_t   key;    ngx_str_t   value;} ngx_keyval_t;typedefstruct {  // 位域用來標示類型等元資訊unsigned    len:28;    unsigned    valid:1;    unsigned    no_cacheable:1;    unsigned    not_found:1;    unsigned    escape:1;    u_char     *data;} ngx_variable_value_t;typedefstruct {    ngx_rbtree_node_t         node;    ngx_str_t                 str;} ngx_str_node_t;

定義了自己的錯誤類型:(原因是系統的strerror和strerror_r函數不是訊號安全的,因此作者將錯誤碼對應的錯誤msg拷貝了一遍,自己維護,自己的函數寫的很簡單,是訊號安全的)
src/os/unix/ngx_errno.h

typedefint               ngx_err_t;// 根據錯誤號碼err,將對應的描述資訊拷貝到errstr,最多拷貝size位元組u_char *ngx_strerror(ngx_err_t err, u_char *errstr, size_t size); ngx_int_t ngx_strerror_init(void);

系統的errno.h中定義了錯誤號碼,多層include後最終錯誤號碼定義於/usr/include/asm-generic/errno.h中。
而strerror和strerror_r函式宣告於string.h

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

以上就介紹了基本資料結構,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.