nginx模块编程学习笔记2–数据类型

在模块种出现了一些nginx特有的数据类型,这里做笔记记录一下。

nginx种数据类型:整型,字符串
src/core/ngx_config.h 种定义了这么集中比较常用的数据类型:

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

/usr/include/stdint.h:123:typedef unsigned long int uintptr_t;

这里是这么定义这两个类型的,根据了操作系统位数不同而定义。

/* Types for `void *’ pointers. */
#if __WORDSIZE == 64
# ifndef __intptr_t_defined
typedef long int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned long int uintptr_t;
#else
# ifndef __intptr_t_defined
typedef int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned int uintptr_t;
#endif

src/core/ngx_string.h中定义了字符串类型

ngx_str_t

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

还有对sting类型的基本处理宏

#define ngx_string(str) { sizeof(str) – 1, (u_char *) str }
#define ngx_null_string { 0, NULL }
#define ngx_str_set(str, text) \
(str)->len = sizeof(text) – 1; (str)->data = (u_char *) text
#define ngx_str_null(str) (str)->len = 0; (str)->data = NULL

。。。。。

Leave a Reply

Your email address will not be published. Required fields are marked *