[njs] Added string functions wrappers.
Dmitry Volyntsev
xeioex at nginx.com
Thu Apr 11 17:14:37 UTC 2019
details: https://hg.nginx.org/njs/rev/e05e9b801355
branches:
changeset: 882:e05e9b801355
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Apr 11 20:09:41 2019 +0300
description:
Added string functions wrappers.
nxt_strlen(), nxt_strchr(), nxt_strlchr().
diffstat:
njs/njs_fs.c | 4 ++--
njs/njs_regexp.c | 4 ++--
njs/njs_shell.c | 20 ++++++++++----------
nxt/nxt_string.h | 26 ++++++++++++++++++++++++++
4 files changed, 40 insertions(+), 14 deletions(-)
diffs (160 lines):
diff -r 5c6ca5b99ab0 -r e05e9b801355 njs/njs_fs.c
--- a/njs/njs_fs.c Thu Apr 11 20:09:41 2019 +0300
+++ b/njs/njs_fs.c Thu Apr 11 20:09:41 2019 +0300
@@ -899,7 +899,7 @@ static njs_ret_t njs_fs_error(njs_vm_t *
njs_object_prop_t *prop;
nxt_lvlhsh_query_t lhq;
- size = description != NULL ? strlen(description) : 0;
+ size = description != NULL ? nxt_strlen(description) : 0;
ret = njs_string_new(vm, &string, (u_char *) description, size, size);
if (nxt_slow_path(ret != NXT_OK)) {
@@ -957,7 +957,7 @@ static njs_ret_t njs_fs_error(njs_vm_t *
}
if (syscall != NULL) {
- size = strlen(syscall);
+ size = nxt_strlen(syscall);
ret = njs_string_new(vm, &string, (u_char *) syscall, size, size);
if (nxt_slow_path(ret != NXT_OK)) {
return NJS_ERROR;
diff -r 5c6ca5b99ab0 -r e05e9b801355 njs/njs_regexp.c
--- a/njs/njs_regexp.c Thu Apr 11 20:09:41 2019 +0300
+++ b/njs/njs_regexp.c Thu Apr 11 20:09:41 2019 +0300
@@ -526,7 +526,7 @@ njs_regexp_prototype_source(njs_vm_t *vm
/* Skip starting "/". */
source = pattern->source + 1;
- size = strlen((char *) source) - pattern->flags;
+ size = nxt_strlen(source) - pattern->flags;
length = nxt_utf8_length(source, size);
return njs_regexp_string_create(vm, retval, source, size, length);
@@ -559,7 +559,7 @@ njs_regexp_to_string(njs_vm_t *vm, njs_v
pattern = value->data.u.regexp->pattern;
source = pattern->source;
- size = strlen((char *) source);
+ size = nxt_strlen(source);
length = nxt_utf8_length(source, size);
return njs_regexp_string_create(vm, retval, source, size, length);
diff -r 5c6ca5b99ab0 -r e05e9b801355 njs/njs_shell.c
--- a/njs/njs_shell.c Thu Apr 11 20:09:41 2019 +0300
+++ b/njs/njs_shell.c Thu Apr 11 20:09:41 2019 +0300
@@ -236,12 +236,12 @@ main(int argc, char **argv)
goto done;
}
- memcpy(path + strlen(path), "/shell", sizeof("/shell"));
+ memcpy(path + nxt_strlen(path), "/shell", sizeof("/shell"));
opts.file = path;
}
vm_options.file.start = (u_char *) opts.file;
- vm_options.file.length = strlen(opts.file);
+ vm_options.file.length = nxt_strlen(opts.file);
}
vm_options.init = !opts.interactive;
@@ -438,7 +438,7 @@ njs_interactive_shell(njs_opts_t *opts,
break;
}
- line.length = strlen((char *) line.start);
+ line.length = nxt_strlen(line.start);
if (line.length == 0) {
continue;
}
@@ -575,7 +575,7 @@ close_fd:
static njs_vm_t *
njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
{
- char *p, *start;
+ u_char *p, *start;
njs_vm_t *vm;
nxt_int_t ret;
nxt_str_t path;
@@ -594,7 +594,7 @@ njs_create_vm(njs_opts_t *opts, njs_vm_o
for (i = 0; i < opts->n_paths; i++) {
path.start = (u_char *) opts->paths[i];
- path.length = strlen(opts->paths[i]);
+ path.length = nxt_strlen(opts->paths[i]);
ret = njs_vm_add_path(vm, &path);
if (ret != NXT_OK) {
@@ -603,16 +603,16 @@ njs_create_vm(njs_opts_t *opts, njs_vm_o
}
}
- start = getenv("NJS_PATH");
+ start = (u_char *) getenv("NJS_PATH");
if (start == NULL) {
return vm;
}
for ( ;; ) {
- p = strchr(start, ':');
+ p = nxt_strchr(start, ':');
- path.start = (u_char *) start;
- path.length = (p != NULL) ? (size_t) (p - start) : strlen(start);
+ path.start = start;
+ path.length = (p != NULL) ? (size_t) (p - start) : nxt_strlen(start);
ret = njs_vm_add_path(vm, &path);
if (ret != NXT_OK) {
@@ -784,7 +784,7 @@ njs_completion_generator(const char *tex
if (state == 0) {
cmpl->phase = 0;
cmpl->index = 0;
- cmpl->length = strlen(text);
+ cmpl->length = nxt_strlen(text);
cmpl->suffix_completions = NULL;
nxt_lvlhsh_each_init(&cmpl->lhe, &njs_variables_hash_proto);
diff -r 5c6ca5b99ab0 -r e05e9b801355 nxt/nxt_string.h
--- a/nxt/nxt_string.h Thu Apr 11 20:09:41 2019 +0300
+++ b/nxt/nxt_string.h Thu Apr 11 20:09:41 2019 +0300
@@ -41,6 +41,27 @@ nxt_upper_case(u_char c)
}
+nxt_inline u_char *
+nxt_strlchr(u_char *p, u_char *last, u_char c)
+{
+ while (p < last) {
+
+ if (*p == c) {
+ return p;
+ }
+
+ p++;
+ }
+
+ return NULL;
+}
+
+
+#define \
+nxt_strlen(s) \
+ strlen((char *) s)
+
+
#define \
nxt_cpymem(dst, src, n) \
(((u_char *) memcpy(dst, src, n)) + (n))
@@ -52,6 +73,11 @@ nxt_strncmp(s1, s2, n)
#define \
+nxt_strchr(s1, c) \
+ (u_char *) strchr((const char *) s1, (int) c)
+
+
+#define \
nxt_memset(buf, c, length) \
(void) memset(buf, c, length)
More information about the nginx-devel
mailing list