summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-06-25 16:51:47 +0300
committerValentin Bartenev <vbart@nginx.com>2018-06-25 16:51:47 +0300
commit1a52d876f7e10d07f58deee6faeaf70a11a6110f (patch)
treef69ba903180b3deac3bba2ee7acda9d34f18d73c
parentaf31012815e20f0c92ed6ea803638a16ba47b0c2 (diff)
downloadunit-1a52d876f7e10d07f58deee6faeaf70a11a6110f.tar.gz
unit-1a52d876f7e10d07f58deee6faeaf70a11a6110f.tar.bz2
Introduced nxt_length() macro.
-rw-r--r--src/go/unit/nxt_go_port_memory.c2
-rw-r--r--src/nxt_app_log.c4
-rw-r--r--src/nxt_application.c8
-rw-r--r--src/nxt_application.h4
-rw-r--r--src/nxt_clang.h4
-rw-r--r--src/nxt_conf.c8
-rw-r--r--src/nxt_conf_validation.c2
-rw-r--r--src/nxt_controller.c16
-rw-r--r--src/nxt_errno.c2
-rw-r--r--src/nxt_h1proto.c16
-rw-r--r--src/nxt_http.h6
-rw-r--r--src/nxt_http_error.c4
-rw-r--r--src/nxt_http_request.c2
-rw-r--r--src/nxt_listen_socket.c10
-rw-r--r--src/nxt_php_sapi.c12
-rw-r--r--src/nxt_python_wsgi.c10
-rw-r--r--src/nxt_random.c2
-rw-r--r--src/nxt_router.c6
-rw-r--r--src/nxt_runtime.c22
-rw-r--r--src/nxt_sockaddr.c4
-rw-r--r--src/nxt_sockaddr.h4
-rw-r--r--src/nxt_sprintf.c4
-rw-r--r--src/nxt_string.h6
-rw-r--r--src/nxt_types.h8
-rw-r--r--src/nxt_upstream_source.h2
-rw-r--r--src/perl/nxt_perl_psgi.c18
-rw-r--r--src/ruby/nxt_ruby.c10
-rw-r--r--src/test/nxt_utf8_test.c4
28 files changed, 101 insertions, 99 deletions
diff --git a/src/go/unit/nxt_go_port_memory.c b/src/go/unit/nxt_go_port_memory.c
index 89530fe8..85b46bed 100644
--- a/src/go/unit/nxt_go_port_memory.c
+++ b/src/go/unit/nxt_go_port_memory.c
@@ -49,7 +49,7 @@ nxt_go_new_port_mmap(nxt_go_process_t *process, nxt_port_id_t id,
return NULL;
}
- name_len = snprintf(name, sizeof(name) - 1,
+ name_len = snprintf(name, nxt_length(name),
NXT_SHM_PREFIX "unit.go.%p", name);
#if (NXT_HAVE_MEMFD_CREATE)
diff --git a/src/nxt_app_log.c b/src/nxt_app_log.c
index 9bd85458..16649ecf 100644
--- a/src/nxt_app_log.c
+++ b/src/nxt_app_log.c
@@ -95,7 +95,7 @@ static nxt_time_string_t nxt_log_error_time_cache = {
(nxt_atomic_uint_t) -1,
nxt_log_error_time,
"%4d/%02d/%02d %02d:%02d:%02d ",
- sizeof("1970/09/28 12:00:00 ") - 1,
+ nxt_length("1970/09/28 12:00:00 "),
NXT_THREAD_TIME_LOCAL,
NXT_THREAD_TIME_MSEC,
};
@@ -115,7 +115,7 @@ static nxt_time_string_t nxt_log_debug_time_cache = {
(nxt_atomic_uint_t) -1,
nxt_log_debug_time,
"%4d/%02d/%02d %02d:%02d:%02d.%03d ",
- sizeof("1970/09/28 12:00:00.000 ") - 1,
+ nxt_length("1970/09/28 12:00:00.000 "),
NXT_THREAD_TIME_LOCAL,
NXT_THREAD_TIME_MSEC,
};
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 186614a0..8b5779c3 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -138,7 +138,7 @@ nxt_discovery_modules(nxt_task_t *task, const char *path)
}
}
- size = sizeof("[]") - 1;
+ size = nxt_length("[]");
module = modules->elts;
n = modules->nelts;
@@ -146,9 +146,9 @@ nxt_discovery_modules(nxt_task_t *task, const char *path)
nxt_debug(task, "module: %d %V %V",
module[i].type, &module[i].version, &module[i].file);
- size += sizeof("{\"type\": ,") - 1;
- size += sizeof(" \"version\": \"\",") - 1;
- size += sizeof(" \"file\": \"\"},") - 1;
+ size += nxt_length("{\"type\": ,");
+ size += nxt_length(" \"version\": \"\",");
+ size += nxt_length(" \"file\": \"\"},");
size += NXT_INT_T_LEN
+ module[i].version.length
diff --git a/src/nxt_application.h b/src/nxt_application.h
index 0ddaeb7c..b5ce3e63 100644
--- a/src/nxt_application.h
+++ b/src/nxt_application.h
@@ -184,7 +184,7 @@ nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg,
#define nxt_app_msg_write_const(task, msg, c) \
- nxt_app_msg_write((task), (msg), (u_char *)(c), sizeof(c) - 1)
+ nxt_app_msg_write((task), (msg), (u_char *) (c), nxt_length(c))
#define nxt_app_msg_write_str(task, msg, str) \
nxt_app_msg_write((task), (msg), (str)->start, (str)->length)
@@ -193,7 +193,7 @@ nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg,
nxt_app_msg_write((task), (msg), (c), nxt_strlen(c))
#define nxt_app_msg_write_nvp(task, msg, n, v) \
- nxt_app_msg_write_nvp_((task), (msg), (u_char *)(n), sizeof(n) - 1, \
+ nxt_app_msg_write_nvp_((task), (msg), (u_char *) (n), nxt_length(n), \
(v)->start, (v)->length)
nxt_inline nxt_int_t nxt_app_msg_write_size(nxt_task_t *task,
diff --git a/src/nxt_clang.h b/src/nxt_clang.h
index a9b8cd9e..a10de08a 100644
--- a/src/nxt_clang.h
+++ b/src/nxt_clang.h
@@ -262,4 +262,8 @@ nxt_trunc_ptr(p, a) \
(u_char *) ((uintptr_t) (p) & ~((uintptr_t) (a) - 1))
+#define nxt_length(s) \
+ (sizeof(s) - 1)
+
+
#endif /* _NXT_CLANG_H_INCLUDED_ */
diff --git a/src/nxt_conf.c b/src/nxt_conf.c
index b3aabcba..34515c1f 100644
--- a/src/nxt_conf.c
+++ b/src/nxt_conf.c
@@ -1878,10 +1878,10 @@ nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty)
switch (value->type) {
case NXT_CONF_VALUE_NULL:
- return sizeof("null") - 1;
+ return nxt_length("null");
case NXT_CONF_VALUE_BOOLEAN:
- return value->u.boolean ? sizeof("true") - 1 : sizeof("false") - 1;
+ return value->u.boolean ? nxt_length("true") : nxt_length("false");
case NXT_CONF_VALUE_INTEGER:
return nxt_conf_json_integer_length(value);
@@ -1952,11 +1952,11 @@ nxt_conf_json_integer_length(nxt_conf_value_t *value)
num = llabs(value->u.integer);
if (num <= 9999) {
- return sizeof("-9999") - 1;
+ return nxt_length("-9999");
}
if (num <= 99999999999LL) {
- return sizeof("-99999999999") - 1;
+ return nxt_length("-99999999999");
}
return NXT_INT64_T_LEN;
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 4fb4720f..f21507d4 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -311,7 +311,7 @@ nxt_conf_vldt_type(nxt_conf_validation_t *vldt, nxt_str_t *name,
nxt_str_t expected;
nxt_bool_t serial;
nxt_uint_t value_type, n, t;
- u_char buf[sizeof(NXT_CONF_VLDT_ANY_TYPE) - 1];
+ u_char buf[nxt_length(NXT_CONF_VLDT_ANY_TYPE)];
static nxt_str_t type_name[] = {
nxt_string("a null"),
diff --git a/src/nxt_controller.c b/src/nxt_controller.c
index 8c098efc..099432f1 100644
--- a/src/nxt_controller.c
+++ b/src/nxt_controller.c
@@ -1167,7 +1167,7 @@ nxt_controller_response(nxt_task_t *task, nxt_controller_request_t *req,
(nxt_atomic_uint_t) -1,
nxt_controller_date,
"%s, %02d %s %4d %02d:%02d:%02d GMT",
- sizeof("Wed, 31 Dec 1986 16:40:00 GMT") - 1,
+ nxt_length("Wed, 31 Dec 1986 16:40:00 GMT"),
NXT_THREAD_TIME_GMT,
NXT_THREAD_TIME_SEC,
};
@@ -1264,13 +1264,13 @@ nxt_controller_response(nxt_task_t *task, nxt_controller_request_t *req,
body->mem.free = nxt_cpymem(body->mem.free, "\r\n", 2);
- size = sizeof("HTTP/1.1 " "\r\n") - 1 + status_line.length
- + sizeof("Server: " NXT_SERVER "\r\n") - 1
- + sizeof("Date: Wed, 31 Dec 1986 16:40:00 GMT\r\n") - 1
- + sizeof("Content-Type: application/json\r\n") - 1
- + sizeof("Content-Length: " "\r\n") - 1 + NXT_SIZE_T_LEN
- + sizeof("Connection: close\r\n") - 1
- + sizeof("\r\n") - 1;
+ size = nxt_length("HTTP/1.1 " "\r\n") + status_line.length
+ + nxt_length("Server: " NXT_SERVER "\r\n")
+ + nxt_length("Date: Wed, 31 Dec 1986 16:40:00 GMT\r\n")
+ + nxt_length("Content-Type: application/json\r\n")
+ + nxt_length("Content-Length: " "\r\n") + NXT_SIZE_T_LEN
+ + nxt_length("Connection: close\r\n")
+ + nxt_length("\r\n");
b = nxt_buf_mem_alloc(c->mem_pool, size, 0);
if (nxt_slow_path(b == NULL)) {
diff --git a/src/nxt_errno.c b/src/nxt_errno.c
index 29f270e0..869a970f 100644
--- a/src/nxt_errno.c
+++ b/src/nxt_errno.c
@@ -41,7 +41,7 @@ nxt_strerror_start(void)
nxt_uint_t err, invalid;
/* The last entry. */
- size = sizeof("Unknown error") - 1;
+ size = nxt_length("Unknown error");
/*
* Linux has holes for error codes 41 and 58, so the loop
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c
index c0be75e2..52a52f79 100644
--- a/src/nxt_h1proto.c
+++ b/src/nxt_h1proto.c
@@ -707,7 +707,7 @@ static const nxt_str_t nxt_http_server_error[] = {
};
-#define UNKNOWN_STATUS_LENGTH (sizeof("HTTP/1.1 65536\r\n") - 1)
+#define UNKNOWN_STATUS_LENGTH nxt_length("HTTP/1.1 65536\r\n")
static void
nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
@@ -766,16 +766,16 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
size = status->length;
/* Trailing CRLF at the end of header. */
- size += sizeof("\r\n") - 1;
+ size += nxt_length("\r\n");
http11 = (h1p->parser.version.s.minor != '0');
if (r->resp.content_length == NULL || r->resp.content_length->skip) {
if (http11) {
h1p->chunked = 1;
- size += sizeof(chunked) - 1;
+ size += nxt_length(chunked);
/* Trailing CRLF will be added by the first chunk header. */
- size -= sizeof("\r\n") - 1;
+ size -= nxt_length("\r\n");
} else {
h1p->keepalive = 0;
@@ -793,7 +793,7 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
if (!field->skip) {
size += field->name_length + field->value_length;
- size += sizeof(": \r\n") - 1;
+ size += nxt_length(": \r\n");
}
} nxt_list_loop;
@@ -824,7 +824,7 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
}
if (h1p->chunked) {
- p = nxt_cpymem(p, chunked, sizeof(chunked) - 1);
+ p = nxt_cpymem(p, chunked, nxt_length(chunked));
/* Trailing CRLF will be added by the first chunk header. */
} else {
@@ -897,7 +897,7 @@ nxt_h1p_chunk_create(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out)
nxt_off_t size;
nxt_buf_t *b, **prev, *header, *tail;
- const size_t chunk_size = 2 * (sizeof("\r\n") - 1) + NXT_OFF_T_HEXLEN;
+ const size_t chunk_size = 2 * nxt_length("\r\n") + NXT_OFF_T_HEXLEN;
static const char tail_chunk[] = "\r\n0\r\n\r\n";
size = 0;
@@ -918,7 +918,7 @@ nxt_h1p_chunk_create(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out)
* memcpy may be inlined with just single 8 byte move operation.
*/
nxt_memcpy(tail->mem.free, tail_chunk, sizeof(tail_chunk));
- tail->mem.free += sizeof(tail_chunk) - 1;
+ tail->mem.free += nxt_length(tail_chunk);
break;
}
diff --git a/src/nxt_http.h b/src/nxt_http.h
index 57c624d7..c6756ec5 100644
--- a/src/nxt_http.h
+++ b/src/nxt_http.h
@@ -76,15 +76,15 @@ typedef union {
#define nxt_http_field_name_set(_field, _name) \
do { \
- (_field)->name_length = sizeof(_name) - 1; \
+ (_field)->name_length = nxt_length(_name); \
(_field)->name = (u_char *) _name; \
} while (0)
#define nxt_http_field_set(_field, _name, _value) \
do { \
- (_field)->name_length = sizeof(_name) - 1; \
- (_field)->value_length = sizeof(_value) - 1; \
+ (_field)->name_length = nxt_length(_name); \
+ (_field)->value_length = nxt_length(_value); \
(_field)->name = (u_char *) _name; \
(_field)->value = (u_char *) _value; \
} while (0)
diff --git a/src/nxt_http_error.c b/src/nxt_http_error.c
index 8b10f508..71f790e0 100644
--- a/src/nxt_http_error.c
+++ b/src/nxt_http_error.c
@@ -49,7 +49,7 @@ nxt_http_request_error(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_field_set(content_type, "Content-Type", "text/html");
r->resp.content_length = NULL;
- r->resp.content_length_n = sizeof(error) - 1;
+ r->resp.content_length_n = nxt_length(error);
r->state = &nxt_http_request_send_error_body_state;
@@ -87,7 +87,7 @@ nxt_http_request_send_error_body(nxt_task_t *task, void *obj, void *data)
out->mem.start = (u_char *) error;
out->mem.pos = out->mem.start;
- out->mem.free = out->mem.start + sizeof(error) - 1;
+ out->mem.free = out->mem.start + nxt_length(error);
out->mem.end = out->mem.free;
out->next = nxt_http_buf_last(r);
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c
index d1a30f0e..2d6ccb42 100644
--- a/src/nxt_http_request.c
+++ b/src/nxt_http_request.c
@@ -282,7 +282,7 @@ nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
(nxt_atomic_uint_t) -1,
nxt_http_date,
"%s, %02d %s %4d %02d:%02d:%02d GMT",
- sizeof("Wed, 31 Dec 1986 16:40:00 GMT") - 1,
+ nxt_length("Wed, 31 Dec 1986 16:40:00 GMT"),
NXT_THREAD_TIME_GMT,
NXT_THREAD_TIME_SEC,
};
diff --git a/src/nxt_listen_socket.c b/src/nxt_listen_socket.c
index a99bc630..0d283c37 100644
--- a/src/nxt_listen_socket.c
+++ b/src/nxt_listen_socket.c
@@ -200,7 +200,7 @@ nxt_listen_socket_remote_size(nxt_listen_socket_t *ls)
* comment in nxt_socket.h.
*/
ls->socklen = offsetof(struct sockaddr_un, sun_path) + 1;
- ls->address_length = sizeof("unix:") - 1;
+ ls->address_length = nxt_length("unix:");
break;
@@ -239,7 +239,7 @@ nxt_listen_socket_pool_min_size(nxt_listen_socket_t *ls)
ls->address_length = NXT_INET6_ADDR_STR_LEN;
size = offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in6)
- + NXT_INET6_ADDR_STR_LEN + (sizeof(":65535") - 1);
+ + NXT_INET6_ADDR_STR_LEN + nxt_length(":65535");
if (IN6_IS_ADDR_UNSPECIFIED(&ls->sockaddr->u.sockaddr_in6.sin6_addr)) {
size += offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in6);
@@ -259,8 +259,8 @@ nxt_listen_socket_pool_min_size(nxt_listen_socket_t *ls)
* sizeof(struct sockaddr_un), see comment in nxt_socket.h.
*/
ls->socklen = 3;
- size = ls->socklen + sizeof("unix:") - 1;
- ls->address_length = sizeof("unix:") - 1;
+ size = ls->socklen + nxt_length("unix:");
+ ls->address_length = nxt_length("unix:");
break;
@@ -271,7 +271,7 @@ nxt_listen_socket_pool_min_size(nxt_listen_socket_t *ls)
ls->address_length = NXT_INET_ADDR_STR_LEN;
size = offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in)
- + NXT_INET_ADDR_STR_LEN + (sizeof(":65535") - 1);
+ + NXT_INET_ADDR_STR_LEN + nxt_length(":65535");
if (ls->sockaddr->u.sockaddr_in.sin_addr.s_addr == INADDR_ANY) {
size += offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in);
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c
index 5aae2f45..f495364a 100644
--- a/src/nxt_php_sapi.c
+++ b/src/nxt_php_sapi.c
@@ -635,8 +635,8 @@ nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
} while(0)
if (SG(request_info).no_headers == 1) {
- RC(nxt_php_write(ctx, default_repsonse, sizeof(default_repsonse) - 1,
- 1, 0));
+ RC(nxt_php_write(ctx, default_repsonse, nxt_length(default_repsonse),
+ 1, 0));
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
@@ -660,21 +660,21 @@ nxt_php_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
RC(nxt_php_write(ctx, buf, len, 0, 0));
} else {
- RC(nxt_php_write(ctx, status_200, sizeof(status_200) - 1, 0, 0));
+ RC(nxt_php_write(ctx, status_200, nxt_length(status_200), 0, 0));
}
- RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
+ RC(nxt_php_write(ctx, cr_lf, nxt_length(cr_lf), 0, 0));
h = zend_llist_get_first_ex(&sapi_headers->headers, &zpos);
while (h) {
RC(nxt_php_write(ctx, (u_char *) h->header, h->header_len, 0, 0));
- RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
+ RC(nxt_php_write(ctx, cr_lf, nxt_length(cr_lf), 0, 0));
h = zend_llist_get_next_ex(&sapi_headers->headers, &zpos);
}
- RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 1, 0));
+ RC(nxt_php_write(ctx, cr_lf, nxt_length(cr_lf), 1, 0));
#undef RC
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index 49063ae9..4b90483e 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -870,7 +870,7 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
string = PyTuple_GET_ITEM(args, 0);
- nxt_python_write(ctx, status, sizeof(status) - 1, 0, 0);
+ nxt_python_write(ctx, status, nxt_length(status), 0, 0);
rc = nxt_python_write_py_str(ctx, string, 0, 0);
if (nxt_slow_path(rc != NXT_OK)) {
@@ -878,7 +878,7 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
"failed to write first argument (not a string?)");
}
- nxt_python_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0);
+ nxt_python_write(ctx, cr_lf, nxt_length(cr_lf), 0, 0);
headers = PyTuple_GET_ITEM(args, 1);
@@ -909,7 +909,7 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
" (not a string?)");
}
- nxt_python_write(ctx, sc_sp, sizeof(sc_sp) - 1, 0, 0);
+ nxt_python_write(ctx, sc_sp, nxt_length(sc_sp), 0, 0);
string = PyTuple_GET_ITEM(tuple, 1);
@@ -920,11 +920,11 @@ nxt_py_start_resp(PyObject *self, PyObject *args)
" (not a string?)");
}
- nxt_python_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0);
+ nxt_python_write(ctx, cr_lf, nxt_length(cr_lf), 0, 0);
}
/* flush headers */
- nxt_python_write(ctx, cr_lf, sizeof(cr_lf) - 1, 1, 0);
+ nxt_python_write(ctx, cr_lf, nxt_length(cr_lf), 1, 0);
Py_INCREF(nxt_py_write_obj);
return nxt_py_write_obj;
diff --git a/src/nxt_random.c b/src/nxt_random.c
index 0731b7fb..b6c9f704 100644
--- a/src/nxt_random.c
+++ b/src/nxt_random.c
@@ -180,7 +180,7 @@ nxt_random_test(nxt_thread_t *thr)
r.count = 400000;
- nxt_random_add(&r, (u_char *) "arc4random", sizeof("arc4random") - 1);
+ nxt_random_add(&r, (u_char *) "arc4random", nxt_length("arc4random"));
/*
* Test arc4random() numbers.
diff --git a/src/nxt_router.c b/src/nxt_router.c
index fa9dd17f..162e7073 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -1880,8 +1880,8 @@ nxt_router_listen_socket_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
error = *p++;
- size = sizeof("listen socket error: ") - 1
- + sizeof("{listener: \"\", code:\"\", message: \"\"}") - 1
+ size = nxt_length("listen socket error: ")
+ + nxt_length("{listener: \"\", code:\"\", message: \"\"}")
+ sa->length + socket_errors[error].length + (in->mem.free - p);
out = nxt_buf_mem_alloc(tmcf->mem_pool, size, 0);
@@ -2753,7 +2753,7 @@ nxt_router_access_log_writer(nxt_task_t *task, nxt_http_request_t *r,
(nxt_atomic_uint_t) -1,
nxt_router_access_log_date,
"%02d/%s/%4d:%02d:%02d:%02d %c%02d%02d",
- sizeof("31/Dec/1986:19:40:00 +0300") - 1,
+ nxt_length("31/Dec/1986:19:40:00 +0300"),
NXT_THREAD_TIME_LOCAL,
NXT_THREAD_TIME_SEC,
};
diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c
index 1dfe2f61..b72cd7d8 100644
--- a/src/nxt_runtime.c
+++ b/src/nxt_runtime.c
@@ -844,7 +844,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--control") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_control, sizeof(no_control) - 1);
+ write(STDERR_FILENO, no_control, nxt_length(no_control));
return NXT_ERROR;
}
@@ -871,7 +871,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--user") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_user, sizeof(no_user) - 1);
+ write(STDERR_FILENO, no_user, nxt_length(no_user));
return NXT_ERROR;
}
@@ -884,7 +884,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--group") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_group, sizeof(no_group) - 1);
+ write(STDERR_FILENO, no_group, nxt_length(no_group));
return NXT_ERROR;
}
@@ -897,7 +897,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--pid") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_pid, sizeof(no_pid) - 1);
+ write(STDERR_FILENO, no_pid, nxt_length(no_pid));
return NXT_ERROR;
}
@@ -910,7 +910,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--log") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_log, sizeof(no_log) - 1);
+ write(STDERR_FILENO, no_log, nxt_length(no_log));
return NXT_ERROR;
}
@@ -923,7 +923,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--modules") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_modules, sizeof(no_modules) - 1);
+ write(STDERR_FILENO, no_modules, nxt_length(no_modules));
return NXT_ERROR;
}
@@ -936,7 +936,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
if (nxt_strcmp(p, "--state") == 0) {
if (*argv == NULL) {
- write(STDERR_FILENO, no_state, sizeof(no_state) - 1);
+ write(STDERR_FILENO, no_state, nxt_length(no_state));
return NXT_ERROR;
}
@@ -953,18 +953,18 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
}
if (nxt_strcmp(p, "--version") == 0) {
- write(STDERR_FILENO, version, sizeof(version) - 1);
+ write(STDERR_FILENO, version, nxt_length(version));
exit(0);
}
if (nxt_strcmp(p, "--help") == 0 || nxt_strcmp(p, "-h") == 0) {
- write(STDOUT_FILENO, help, sizeof(help) - 1);
+ write(STDOUT_FILENO, help, nxt_length(help));
if (sizeof(NXT_GROUP) == 1) {
- write(STDOUT_FILENO, primary, sizeof(primary) - 1);
+ write(STDOUT_FILENO, primary, nxt_length(primary));
} else {
- write(STDOUT_FILENO, group, sizeof(group) - 1);
+ write(STDOUT_FILENO, group, nxt_length(group));
}
exit(0);
diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c
index 0df40a1f..9bf32a11 100644
--- a/src/nxt_sockaddr.c
+++ b/src/nxt_sockaddr.c
@@ -203,7 +203,7 @@ nxt_getsockname(nxt_task_t *task, nxt_mp_t *mp, nxt_socket_t s)
#if (NXT_HAVE_UNIX_DOMAIN)
case AF_UNIX:
- length = sizeof("unix:") - 1 + socklen;
+ length = nxt_length("unix:") + socklen;
#endif
break;
@@ -515,7 +515,7 @@ nxt_inet6_ntop(u_char *addr, u_char *buf, u_char *end)
nxt_uint_t i, zero_start, last_zero_start;
const size_t max_inet6_length =
- sizeof("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") - 1;
+ nxt_length("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
if (buf + max_inet6_length > end) {
return buf;
diff --git a/src/nxt_sockaddr.h b/src/nxt_sockaddr.h
index ca5d8054..aa4da5d2 100644
--- a/src/nxt_sockaddr.h
+++ b/src/nxt_sockaddr.h
@@ -99,10 +99,10 @@ NXT_EXPORT nxt_int_t nxt_inet6_addr(struct in6_addr *in6_addr, u_char *buf,
#endif
-#define NXT_INET_ADDR_STR_LEN (sizeof("255.255.255.255:65535") - 1)
+#define NXT_INET_ADDR_STR_LEN nxt_length("255.255.255.255:65535")
#define NXT_INET6_ADDR_STR_LEN \
- (sizeof("[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535") - 1)
+ nxt_length("[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535")
#define nxt_sockaddr_size(sa) \
diff --git a/src/nxt_sprintf.c b/src/nxt_sprintf.c
index 789d58f1..f2e2b414 100644
--- a/src/nxt_sprintf.c
+++ b/src/nxt_sprintf.c
@@ -380,13 +380,13 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
if (nxt_slow_path(isnan(f))) {
p = (u_char *) nan;
- length = sizeof(nan) - 1;
+ length = nxt_length(nan);
goto copy;
} else if (nxt_slow_path(isinf(f))) {
p = (u_char *) infinity;
- length = sizeof(infinity) - 1;
+ length = nxt_length(infinity);
goto copy;
}
diff --git a/src/nxt_string.h b/src/nxt_string.h
index 2a3d55ea..e6d32fa6 100644
--- a/src/nxt_string.h
+++ b/src/nxt_string.h
@@ -24,7 +24,7 @@ nxt_isdigit(c) \
#define NXT_CR (u_char) 13
#define NXT_LF (u_char) 10
#define NXT_CRLF "\x0d\x0a"
-#define NXT_CRLF_SIZE (sizeof(NXT_CRLF) - 1)
+#define NXT_CRLF_SIZE nxt_length(NXT_CRLF)
#define NXT_LINEFEED_SIZE 1
@@ -116,7 +116,7 @@ typedef struct {
} nxt_str_t;
-#define nxt_string(str) { sizeof(str) - 1, (u_char *) str }
+#define nxt_string(str) { nxt_length(str), (u_char *) str }
#define nxt_string_zero(str) { sizeof(str), (u_char *) str }
#define nxt_null_string { 0, NULL }
@@ -124,7 +124,7 @@ typedef struct {
#define \
nxt_str_set(str, text) \
do { \
- (str)->length = sizeof(text) - 1; \
+ (str)->length = nxt_length(text); \
(str)->start = (u_char *) text; \
} while (0)
diff --git a/src/nxt_types.h b/src/nxt_types.h
index 98e23222..03e9c187 100644
--- a/src/nxt_types.h
+++ b/src/nxt_types.h
@@ -76,11 +76,11 @@ typedef time_t nxt_time_t;
#endif
-#define NXT_INT64_T_LEN (sizeof("-9223372036854775808") - 1)
-#define NXT_INT32_T_LEN (sizeof("-2147483648") - 1)
+#define NXT_INT64_T_LEN nxt_length("-9223372036854775808")
+#define NXT_INT32_T_LEN nxt_length("-2147483648")
-#define NXT_INT64_T_HEXLEN (sizeof("FFFFFFFFFFFFFFFF") - 1)
-#define NXT_INT32_T_HEXLEN (sizeof("FFFFFFFF") - 1)
+#define NXT_INT64_T_HEXLEN nxt_length("FFFFFFFFFFFFFFFF")
+#define NXT_INT32_T_HEXLEN nxt_length("FFFFFFFF")
#define NXT_INT64_T_MAX 0x7FFFFFFFFFFFFFFFLL
#define NXT_INT32_T_MAX 0x7FFFFFFF
diff --git a/src/nxt_upstream_source.h b/src/nxt_upstream_source.h
index 4189a356..143b8d0c 100644
--- a/src/nxt_upstream_source.h
+++ b/src/nxt_upstream_source.h
@@ -69,7 +69,7 @@ struct nxt_upstream_source_s {
#define NXT_UPSTREAM_NAME_VALUE_MIN_SIZE \
offsetof(nxt_http_upstream_header_t, name)
-#define nxt_upstream_name_value(s) sizeof(s) - 1, s
+#define nxt_upstream_name_value(s) nxt_length(s), s
NXT_EXPORT nxt_int_t nxt_upstream_header_hash_add(nxt_mp_t *mp,
diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c
index 16bcf79f..3619dcd0 100644
--- a/src/perl/nxt_perl_psgi.c
+++ b/src/perl/nxt_perl_psgi.c
@@ -158,9 +158,9 @@ nxt_perl_psgi_http_write_status_str(nxt_task_t *task, nxt_app_wmsg_t *wmsg,
\
} while (0)
- RC_WRT((const u_char *) "Status: ", (sizeof("Status: ") - 1), 0);
+ RC_WRT((const u_char *) "Status: ", nxt_length("Status: "), 0);
RC_WRT(http_status->start, http_status->length, 0);
- RC_WRT((u_char *) "\r\n", (sizeof("\r\n") - 1), 0);
+ RC_WRT((u_char *) "\r\n", nxt_length("\r\n"), 0);
#undef RC_WRT
@@ -799,12 +799,10 @@ nxt_perl_psgi_result_head(PerlInterpreter *my_perl, SV *sv_head,
if ((i % 2) == 0) {
rc = nxt_app_msg_write_raw(task, wmsg,
- (u_char *) ": ",
- (sizeof(": ") - 1));
+ (u_char *) ": ", nxt_length(": "));
} else {
rc = nxt_app_msg_write_raw(task, wmsg,
- (u_char *) "\r\n",
- (sizeof("\r\n") - 1));
+ (u_char *) "\r\n", nxt_length("\r\n"));
}
if (nxt_slow_path(rc != NXT_OK)) {
@@ -973,8 +971,8 @@ nxt_perl_psgi_result_array(PerlInterpreter *my_perl, SV *result,
}
if (array_len < 1) {
- rc = nxt_app_msg_write_raw(task, wmsg, (u_char *) "\r\n",
- (sizeof("\r\n") - 1));
+ rc = nxt_app_msg_write_raw(task, wmsg,
+ (u_char *) "\r\n", nxt_length("\r\n"));
if (nxt_slow_path(rc != NXT_OK)) {
nxt_log_error(NXT_LOG_ERR, task->log,
@@ -1001,8 +999,8 @@ nxt_perl_psgi_result_array(PerlInterpreter *my_perl, SV *result,
return rc;
}
- rc = nxt_app_msg_write_raw(task, wmsg, (u_char *) "\r\n",
- (sizeof("\r\n") - 1));
+ rc = nxt_app_msg_write_raw(task, wmsg,
+ (u_char *) "\r\n", nxt_length("\r\n"));
if (nxt_slow_path(rc != NXT_OK)) {
nxt_log_error(NXT_LOG_ERR, task->log,
diff --git a/src/ruby/nxt_ruby.c b/src/ruby/nxt_ruby.c
index 230c5b98..e9fa01c8 100644
--- a/src/ruby/nxt_ruby.c
+++ b/src/ruby/nxt_ruby.c
@@ -581,7 +581,7 @@ nxt_ruby_rack_result_status(VALUE result)
}
rc = nxt_ruby_write(nxt_ruby_run_ctx.task, nxt_ruby_run_ctx.wmsg,
- (u_char *) "Status: ", (sizeof("Status: ") - 1), 0, 0);
+ (u_char *) "Status: ", nxt_length("Status: "), 0, 0);
if (nxt_slow_path(rc != NXT_OK)) {
return NXT_ERROR;
}
@@ -593,7 +593,7 @@ nxt_ruby_rack_result_status(VALUE result)
}
rc = nxt_ruby_write(nxt_ruby_run_ctx.task, nxt_ruby_run_ctx.wmsg,
- (u_char *) "\r\n", (sizeof("\r\n") - 1), 0, 0);
+ (u_char *) "\r\n", nxt_length("\r\n"), 0, 0);
if (nxt_slow_path(rc != NXT_OK)) {
return NXT_ERROR;
}
@@ -643,7 +643,7 @@ nxt_ruby_rack_result_headers(VALUE result)
}
rc = nxt_ruby_write(nxt_ruby_run_ctx.task, nxt_ruby_run_ctx.wmsg,
- (u_char *) "\r\n", (sizeof("\r\n") - 1), 0, 0);
+ (u_char *) "\r\n", nxt_length("\r\n"), 0, 0);
if (nxt_slow_path(rc != NXT_OK)) {
return NXT_ERROR;
}
@@ -729,7 +729,7 @@ nxt_ruby_head_send_part(const char *key, size_t key_size,
}
rc = nxt_app_msg_write_raw(nxt_ruby_run_ctx.task, nxt_ruby_run_ctx.wmsg,
- (u_char *) ": ", (sizeof(": ") - 1));
+ (u_char *) ": ", nxt_length(": "));
if (nxt_slow_path(rc != NXT_OK)) {
return rc;
}
@@ -741,7 +741,7 @@ nxt_ruby_head_send_part(const char *key, size_t key_size,
}
return nxt_app_msg_write_raw(nxt_ruby_run_ctx.task, nxt_ruby_run_ctx.wmsg,
- (u_char *) "\r\n", (sizeof("\r\n") - 1));
+ (u_char *) "\r\n", nxt_length("\r\n"));
}
diff --git a/src/test/nxt_utf8_test.c b/src/test/nxt_utf8_test.c
index 7a6dcd33..bca9a737 100644
--- a/src/test/nxt_utf8_test.c
+++ b/src/test/nxt_utf8_test.c
@@ -178,8 +178,8 @@ nxt_utf8_test(nxt_thread_t *thr)
n = nxt_utf8_casecmp((u_char *) "ABC АБВ ΑΒΓ",
(u_char *) "abc абв αβγ",
- sizeof("ABC АБВ ΑΒΓ") - 1,
- sizeof("abc абв αβγ") - 1);
+ nxt_length("ABC АБВ ΑΒΓ"),
+ nxt_length("abc абв αβγ"));
if (n != 0) {
nxt_log_alert(thr->log, "nxt_utf8_casecmp() failed");