typedef struct {
ngx_str_t key;
ngx_str_t value;
} ngx_keyval_t;
实例
#include <stdio.h>
#include <ngx_config.h>
#include <ngx_conf_file.h>
#include <nginx.h>
#include <ngx_core.h>
#include <ngx_string.h>
#include <ngx_palloc.h>
volatile ngx_cycle_t *ngx_cycle;
void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
{
}
int
main(int argc, char *argv[])
{
//ngx_str_t t1, t2;
ngx_str_t t1 = ngx_string("bei jing");
ngx_str_t t2 = ngx_string("shang hai");
ngx_keyval_t kv = {t1, t2};
printf("<key>\n");
printf("key.len = %lu\n", kv.key.len);
printf("key.data = %s\n\n", kv.key.data);
printf("<value>:\n");
printf("value.len = %lu\n", kv.value.len);
printf("value.data = %s\n", kv.value.data);
return 0;
}
执行:
gcc -c -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g
-I ../../objs/
-I ../os/unix/
-I../core/
-I /usr/local/opt/pcre/include/
-I../event/
-I../os/
./j_str.c -o ./j_str.o
gcc -o ./j_str ./j_str.o
../../objs/src/core/ngx_string.o
../../objs/src/os/unix/ngx_alloc.o
../../objs/src/core/ngx_palloc.o
结果:
<key>
key.len = 8
key.data = bei jing
<value>:
value.len = 9
value.data = shang ha