ngx_str_set() and ngx_str_null()
diff --git a/src/core/nginx.c b/src/core/nginx.c
index a5fbccd..80a5d18 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -859,14 +859,11 @@
#else
#ifdef NGX_CONF_PREFIX
- cycle->conf_prefix.len = sizeof(NGX_CONF_PREFIX) - 1;
- cycle->conf_prefix.data = (u_char *) NGX_CONF_PREFIX;
+ ngx_str_set(&cycle->conf_prefix, NGX_CONF_PREFIX);
#else
- cycle->conf_prefix.len = sizeof(NGX_PREFIX) - 1;
- cycle->conf_prefix.data = (u_char *) NGX_PREFIX;
+ ngx_str_set(&cycle->conf_prefix, NGX_PREFIX);
#endif
- cycle->prefix.len = sizeof(NGX_PREFIX) - 1;
- cycle->prefix.data = (u_char *) NGX_PREFIX;
+ ngx_str_set(&cycle->prefix, NGX_PREFIX);
#endif
}
@@ -876,8 +873,7 @@
cycle->conf_file.data = ngx_conf_file;
} else {
- cycle->conf_file.len = sizeof(NGX_CONF_PATH) - 1;
- cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
+ ngx_str_set(&cycle->conf_file, NGX_CONF_PATH);
}
if (ngx_conf_full_name(cycle, &cycle->conf_file, 0) != NGX_OK) {
@@ -993,8 +989,7 @@
if (ccf->pid.len == 0) {
- ccf->pid.len = sizeof(NGX_PID_PATH) - 1;
- ccf->pid.data = (u_char *) NGX_PID_PATH;
+ ngx_str_set(&ccf->pid, NGX_PID_PATH);
}
if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) {
@@ -1042,8 +1037,7 @@
if (ccf->lock_file.len == 0) {
- ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1;
- ccf->lock_file.data = (u_char *) NGX_LOCK_PATH;
+ ngx_str_set(&ccf->lock_file, NGX_LOCK_PATH);
}
if (ngx_conf_full_name(cycle, &ccf->lock_file, 0) != NGX_OK) {
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 6d5f510..20d9af9 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -903,8 +903,7 @@
ngx_open_file_t *file;
#if (NGX_SUPPRESS_WARN)
- full.len = 0;
- full.data = NULL;
+ ngx_str_null(&full);
#endif
if (name->len) {
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index b5160f3..ed6d842 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -825,8 +825,7 @@
ngx_str_t file, buf;
ngx_dir_t dir;
- buf.len = 0;
- buf.data = NULL;
+ ngx_str_null(&buf);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
"walk tree \"%V\"", tree);
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 770a590..c0485c6 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -429,8 +429,7 @@
value = cf->args->elts;
if (ngx_strcmp(value[1].data, "stderr") == 0) {
- name.len = 0;
- name.data = NULL;
+ ngx_str_null(&name);
} else {
name = value[1];
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index b29bdda..53b9422 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -38,6 +38,9 @@
#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
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)