]> git.kaiwu.me - njs.git/commitdiff
Using nxt_printf() everywhere.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Mar 2019 16:45:58 +0000 (19:45 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Mar 2019 16:45:58 +0000 (19:45 +0300)
25 files changed:
auto/make
njs/njs_builtin.c
njs/njs_crypto.c
njs/njs_date.c
njs/njs_disassembler.c
njs/njs_error.c
njs/njs_extern.c
njs/njs_fs.c
njs/njs_module.c
njs/njs_number.c
njs/njs_number.h
njs/njs_parser.c
njs/njs_regexp.c
njs/njs_shell.c
njs/njs_time.c
njs/njs_vm.c
njs/test/njs_benchmark.c
njs/test/njs_interactive_test.c
njs/test/njs_unit_test.c
nxt/nxt_sprintf.h
nxt/nxt_trace.c
nxt/test/lvlhsh_unit_test.c
nxt/test/random_unit_test.c
nxt/test/rbtree_unit_test.c
nxt/test/utf8_unit_test.c

index 27153000c7a99e915698fbe66dd11a11895a5b00..7c43d690e0056356673d4646288919408f3b5a8e 100644 (file)
--- a/auto/make
+++ b/auto/make
@@ -103,7 +103,7 @@ $NXT_BUILD_DIR/$nxt_bin: $nxt_src \\
        \$(NXT_CC) -o $NXT_BUILD_DIR/$nxt_bin \$(NXT_CFLAGS) \\
                \$(NXT_LIB_INCS) $nxt_dep_flags \\
                $nxt_src $NXT_BUILD_DIR/libnxt.a \\
-               $nxt_dep_post
+               $nxt_dep_post -lm
 
 -include $NXT_BUILD_DIR/$nxt_dep
 
index 985e5f4893584580f46aa7594847ea7b0c7f1057..6d715a0ed4645e077c851829bf22e56778c6b584 100644 (file)
@@ -15,7 +15,6 @@
 #include <njs_fs.h>
 #include <njs_crypto.h>
 #include <string.h>
-#include <stdio.h>
 
 
 typedef struct {
index 6ede1535346bf277938c72f8b7b44a92b62676d8..e8a486160e038bcb318dea7028ed8b43f04138a4 100644 (file)
@@ -9,7 +9,6 @@
 #include <nxt_sha1.h>
 #include <nxt_sha2.h>
 #include <njs_crypto.h>
-#include <stdio.h>
 #include <string.h>
 #include <math.h>
 
index eabee2ef0f36238fb83f477b9b3f4582f3c0fd6a..04e61ec1b627ba335e24555fd4557d1b96a4f67f 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <njs_core.h>
 #include <njs_date.h>
-#include <stdio.h>
 #include <string.h>
 #include <sys/time.h>
 #include <time.h>
index 2780f7262980994376b42581e12da64295034829..2d82ce3cde79ee8dcdd5da52b6100891240fdf89 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include <njs_core.h>
-#include <stdio.h>
 
 
 static void njs_disassemble(u_char *start, u_char *end);
@@ -139,8 +138,7 @@ njs_disassembler(njs_vm_t *vm)
     n = vm->code->items;
 
     while (n != 0) {
-        printf("%.*s:%.*s\n", (int) code->file.length, code->file.start,
-               (int) code->name.length, code->name.start);
+        nxt_printf("%V:%V\n", &code->file, &code->name);
         njs_disassemble(code->start, code->end);
         code++;
         n--;
@@ -190,9 +188,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_array) {
             array = (njs_vmcode_array_t *) p;
 
-            printf("%05zd ARRAY             %04zX %zd%s\n",
-                   p - start, (size_t) array->retval, (size_t) array->length,
-                   array->code.ctor ? " INIT" : "");
+            nxt_printf("%05uz ARRAY             %04Xz %uz%s\n",
+                       p - start, (size_t) array->retval,
+                       (size_t) array->length, array->code.ctor ? " INIT" : "");
 
             p += sizeof(njs_vmcode_array_t);
 
@@ -203,9 +201,9 @@ njs_disassemble(u_char *start, u_char *end)
             cond_jump = (njs_vmcode_cond_jump_t *) p;
             sign = (cond_jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP IF TRUE      %04zX %s%zd\n",
-                   p - start, (size_t) cond_jump->cond, sign,
-                   (size_t) cond_jump->offset);
+            nxt_printf("%05uz JUMP IF TRUE      %04Xz %s%uz\n",
+                       p - start, (size_t) cond_jump->cond, sign,
+                       (size_t) cond_jump->offset);
 
             p += sizeof(njs_vmcode_cond_jump_t);
 
@@ -216,9 +214,9 @@ njs_disassemble(u_char *start, u_char *end)
             cond_jump = (njs_vmcode_cond_jump_t *) p;
             sign = (cond_jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP IF FALSE     %04zX %s%zd\n",
-                   p - start, (size_t) cond_jump->cond, sign,
-                   (size_t) cond_jump->offset);
+            nxt_printf("%05uz JUMP IF FALSE     %04Xz %s%uz\n",
+                       p - start, (size_t) cond_jump->cond, sign,
+                       (size_t) cond_jump->offset);
 
             p += sizeof(njs_vmcode_cond_jump_t);
 
@@ -229,8 +227,8 @@ njs_disassemble(u_char *start, u_char *end)
             jump = (njs_vmcode_jump_t *) p;
             sign = (jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP              %s%zd\n",
-                   p - start, sign, (size_t) jump->offset);
+            nxt_printf("%05uz JUMP              %s%uz\n",
+                       p - start, sign, (size_t) jump->offset);
 
             p += sizeof(njs_vmcode_jump_t);
 
@@ -240,9 +238,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_if_equal_jump) {
             equal = (njs_vmcode_equal_jump_t *) p;
 
-            printf("%05zd JUMP IF EQUAL     %04zX %04zX +%zd\n",
-                   p - start, (size_t) equal->value1, (size_t) equal->value2,
-                   (size_t) equal->offset);
+            nxt_printf("%05uz JUMP IF EQUAL     %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) equal->value1,
+                       (size_t) equal->value2, (size_t) equal->offset);
 
             p += sizeof(njs_vmcode_equal_jump_t);
 
@@ -252,9 +250,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_test_if_true) {
             test_jump = (njs_vmcode_test_jump_t *) p;
 
-            printf("%05zd TEST IF TRUE      %04zX %04zX +%zd\n",
-                   p - start, (size_t) test_jump->retval,
-                   (size_t) test_jump->value, (size_t) test_jump->offset);
+            nxt_printf("%05uz TEST IF TRUE      %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) test_jump->retval,
+                       (size_t) test_jump->value, (size_t) test_jump->offset);
 
             p += sizeof(njs_vmcode_test_jump_t);
 
@@ -264,9 +262,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_test_if_false) {
             test_jump = (njs_vmcode_test_jump_t *) p;
 
-            printf("%05zd TEST IF FALSE     %04zX %04zX +%zd\n",
-                   p - start, (size_t) test_jump->retval,
-                   (size_t) test_jump->value, (size_t) test_jump->offset);
+            nxt_printf("%05uz TEST IF FALSE     %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) test_jump->retval,
+                       (size_t) test_jump->value, (size_t) test_jump->offset);
 
             p += sizeof(njs_vmcode_test_jump_t);
 
@@ -276,9 +274,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_function_frame) {
             function = (njs_vmcode_function_frame_t *) p;
 
-            printf("%05zd FUNCTION FRAME    %04zX %zd%s\n",
-                   p - start, (size_t) function->name, function->nargs,
-                   function->code.ctor ? " CTOR" : "");
+            nxt_printf("%05uz FUNCTION FRAME    %04Xz %uz%s\n",
+                       p - start, (size_t) function->name, function->nargs,
+                       function->code.ctor ? " CTOR" : "");
 
             p += sizeof(njs_vmcode_function_frame_t);
 
@@ -288,9 +286,10 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_method_frame) {
             method = (njs_vmcode_method_frame_t *) p;
 
-            printf("%05zd METHOD FRAME      %04zX %04zX %zd%s\n",
-                   p - start, (size_t) method->object, (size_t) method->method,
-                   method->nargs, method->code.ctor ? " CTOR" : "");
+            nxt_printf("%05uz METHOD FRAME      %04Xz %04Xz %uz%s\n",
+                       p - start, (size_t) method->object,
+                       (size_t) method->method, method->nargs,
+                       method->code.ctor ? " CTOR" : "");
 
 
             p += sizeof(njs_vmcode_method_frame_t);
@@ -300,10 +299,10 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_property_foreach) {
             prop_foreach = (njs_vmcode_prop_foreach_t *) p;
 
-            printf("%05zd PROPERTY FOREACH  %04zX %04zX +%zd\n",
-                   p - start, (size_t) prop_foreach->next,
-                   (size_t) prop_foreach->object,
-                   (size_t) prop_foreach->offset);
+            nxt_printf("%05uz PROPERTY FOREACH  %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) prop_foreach->next,
+                       (size_t) prop_foreach->object,
+                       (size_t) prop_foreach->offset);
 
 
             p += sizeof(njs_vmcode_prop_foreach_t);
@@ -313,10 +312,10 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_property_next) {
             prop_next = (njs_vmcode_prop_next_t *) p;
 
-            printf("%05zd PROPERTY NEXT     %04zX %04zX %04zX %zd\n",
-                   p - start, (size_t) prop_next->retval,
-                   (size_t) prop_next->object, (size_t) prop_next->next,
-                   (size_t) prop_next->offset);
+            nxt_printf("%05uz PROPERTY NEXT     %04Xz %04Xz %04Xz %uz\n",
+                       p - start, (size_t) prop_next->retval,
+                       (size_t) prop_next->object, (size_t) prop_next->next,
+                       (size_t) prop_next->offset);
 
             p += sizeof(njs_vmcode_prop_next_t);
 
@@ -326,10 +325,10 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_try_start) {
             try_start = (njs_vmcode_try_start_t *) p;
 
-            printf("%05zd TRY START         %04zX %04zX +%zd\n",
-                   p - start, (size_t) try_start->exception_value,
-                   (size_t) try_start->exit_value,
-                   (size_t) try_start->offset);
+            nxt_printf("%05uz TRY START         %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) try_start->exception_value,
+                       (size_t) try_start->exit_value,
+                       (size_t) try_start->offset);
 
             p += sizeof(njs_vmcode_try_start_t);
 
@@ -339,9 +338,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_try_break) {
             try_tramp = (njs_vmcode_try_trampoline_t *) p;
 
-            printf("%05zd TRY BREAK         %04zX %zd\n",
-                   p - start, (size_t) try_tramp->exit_value,
-                   (size_t) try_tramp->offset);
+            nxt_printf("%05uz TRY BREAK         %04Xz %uz\n",
+                       p - start, (size_t) try_tramp->exit_value,
+                       (size_t) try_tramp->offset);
 
             p += sizeof(njs_vmcode_try_trampoline_t);
 
@@ -351,9 +350,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_try_continue) {
             try_tramp = (njs_vmcode_try_trampoline_t *) p;
 
-            printf("%05zd TRY CONTINUE      %04zX %zd\n",
-                   p - start, (size_t) try_tramp->exit_value,
-                   (size_t) try_tramp->offset);
+            nxt_printf("%05uz TRY CONTINUE      %04Xz %uz\n",
+                       p - start, (size_t) try_tramp->exit_value,
+                       (size_t) try_tramp->offset);
 
             p += sizeof(njs_vmcode_try_trampoline_t);
 
@@ -363,10 +362,10 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_try_return) {
             try_return = (njs_vmcode_try_return_t *) p;
 
-            printf("%05zd TRY RETURN        %04zX %04zX +%zd\n",
-                   p - start, (size_t) try_return->save,
-                   (size_t) try_return->retval,
-                   (size_t) try_return->offset);
+            nxt_printf("%05uz TRY RETURN        %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) try_return->save,
+                       (size_t) try_return->retval,
+                       (size_t) try_return->offset);
 
             p += sizeof(njs_vmcode_try_return_t);
 
@@ -376,9 +375,9 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_catch) {
             catch = (njs_vmcode_catch_t *) p;
 
-            printf("%05zd CATCH             %04zX +%zd\n",
-                   p - start, (size_t) catch->exception,
-                   (size_t) catch->offset);
+            nxt_printf("%05uz CATCH             %04Xz +%uz\n",
+                       p - start, (size_t) catch->exception,
+                       (size_t) catch->offset);
 
             p += sizeof(njs_vmcode_catch_t);
 
@@ -388,8 +387,8 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_try_end) {
             try_end = (njs_vmcode_try_end_t *) p;
 
-            printf("%05zd TRY END           +%zd\n",
-                   p - start, (size_t) try_end->offset);
+            nxt_printf("%05uz TRY END           +%uz\n",
+                       p - start, (size_t) try_end->offset);
 
             p += sizeof(njs_vmcode_try_end_t);
 
@@ -399,11 +398,11 @@ njs_disassemble(u_char *start, u_char *end)
         if (operation == njs_vmcode_finally) {
             finally = (njs_vmcode_finally_t *) p;
 
-            printf("%05zd TRY FINALLY       %04zX %04zX +%zd +%zd\n",
-                   p - start, (size_t) finally->retval,
-                   (size_t) finally->exit_value,
-                   (size_t) finally->continue_offset,
-                   (size_t) finally->break_offset);
+            nxt_printf("%05uz TRY FINALLY       %04Xz %04Xz +%uz +%uz\n",
+                       p - start, (size_t) finally->retval,
+                       (size_t) finally->exit_value,
+                       (size_t) finally->continue_offset,
+                       (size_t) finally->break_offset);
 
             p += sizeof(njs_vmcode_finally_t);
 
@@ -420,24 +419,24 @@ njs_disassemble(u_char *start, u_char *end)
                 if (code_name->size == sizeof(njs_vmcode_3addr_t)) {
                     code3 = (njs_vmcode_3addr_t *) p;
 
-                    printf("%05zd %*s  %04zX %04zX %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code3->dst, (size_t) code3->src1,
-                           (size_t) code3->src2);
+                    nxt_printf("%05uz %*s  %04Xz %04Xz %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code3->dst, (size_t) code3->src1,
+                               (size_t) code3->src2);
 
                 } else if (code_name->size == sizeof(njs_vmcode_2addr_t)) {
                     code2 = (njs_vmcode_2addr_t *) p;
 
-                    printf("%05zd %*s  %04zX %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code2->dst, (size_t) code2->src);
+                    nxt_printf("%05uz %*s  %04Xz %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code2->dst, (size_t) code2->src);
 
                 } else if (code_name->size == sizeof(njs_vmcode_1addr_t)) {
                     code1 = (njs_vmcode_1addr_t *) p;
 
-                    printf("%05zd %*s  %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code1->index);
+                    nxt_printf("%05uz %*s  %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code1->index);
                 }
 
                 p += code_name->size;
@@ -450,8 +449,8 @@ njs_disassemble(u_char *start, u_char *end)
 
         } while (n != 0);
 
-        printf("%05zd UNKNOWN           %04zX\n",
-               p - start, (size_t) (uintptr_t) operation);
+        nxt_printf("%05uz UNKNOWN           %04Xz\n",
+                   p - start, (size_t) (uintptr_t) operation);
 
         p += sizeof(njs_vmcode_operation_t);
 
index 971e71c06f0932cc3200281adbaafd07d6f6b77b..26e2130e5896599742911be81f31d0549ce047e5 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include <njs_core.h>
-#include <stdio.h>
 #include <string.h>
 #include <math.h>
 
index 57790d730f0a6be509f9fb995274f543e1ab0bfd..c46003143ac8f1bf6cda433f7352e73cf6156a16 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <njs_core.h>
 #include <string.h>
-#include <stdio.h>
 
 
 typedef struct njs_extern_part_s  njs_extern_part_t;
index 7805f56ebe6b69fb884aa35f5ec5908470db8a00..516b820cd7b8c4bc22ff408dfbb42aea23f4f21a 100644 (file)
@@ -10,7 +10,6 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <errno.h>
-#include <stdio.h>
 
 
 typedef struct {
index 2ce782996c9cf12ba06569ac0e4c7d85febbdaef..35f737253cdf55dbaf11a056776e806a53a74025 100644 (file)
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_module.h>
 #include <string.h>
-#include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
index 6c3a066ec2836ddced0137cc99afd8519ad02dfc..3f8c116561874b4c147859c3a658c1fd441b95de 100644 (file)
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <math.h>
 #include <string.h>
-#include <stdio.h>
 #include <float.h>
 
 
index 769ef3bdae3be6af40541ef505efb848650617a8..d3b699d9b058b4caf3af43864cfd825a87055bbc 100644 (file)
@@ -9,7 +9,6 @@
 
 
 #include <math.h>
-#include <stdio.h>
 
 
 uint32_t njs_value_to_index(const njs_value_t *value);
index 9b6b6a7ba2cc64296fba882c547d51da73f7ce55..a3baf2a5bee37422e661265ad62d6792784365ad 100644 (file)
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_regexp.h>
 #include <string.h>
-#include <stdio.h>
 
 
 static njs_ret_t njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser,
index 5f469b2234b0f11d62db208a650684513a0423dd..dac8b84c549fb422df92e45dfdba4f5ea3ce2142 100644 (file)
@@ -9,7 +9,6 @@
 #include <njs_regexp_pattern.h>
 
 #include <string.h>
-#include <stdio.h>
 
 
 static void *njs_regexp_malloc(size_t size, void *memory_data);
index 4849557cb5c659c29a894fcf8e39fdfef2103122..9f50743813fba0f8d3d9c044781ed5ca12f106c4 100644 (file)
 #include <time.h>
 #include <errno.h>
 #include <string.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <locale.h>
 
+#include <stdio.h>
 #include <readline.h>
 
 
@@ -214,7 +214,7 @@ main(int argc, char **argv)
     }
 
     if (opts.version != 0) {
-        printf("%s\n", NJS_VERSION);
+        nxt_printf("%s\n", NJS_VERSION);
         ret = NXT_OK;
         goto done;
     }
@@ -225,7 +225,7 @@ main(int argc, char **argv)
         if (opts.file == NULL) {
             p = getcwd(path, sizeof(path));
             if (p == NULL) {
-                fprintf(stderr, "getcwd() failed:%s\n", strerror(errno));
+                nxt_error("getcwd() failed:%s\n", strerror(errno));
                 ret = NXT_ERROR;
                 goto done;
             }
@@ -316,7 +316,7 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
                 opts->n_paths++;
                 paths = realloc(opts->paths, opts->n_paths * sizeof(char *));
                 if (paths == NULL) {
-                    fprintf(stderr, "failed to add path\n");
+                    nxt_error("failed to add path\n");
                     return NXT_ERROR;
                 }
 
@@ -325,7 +325,7 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
                 break;
             }
 
-            fprintf(stderr, "option \"-p\" requires directory name\n");
+            nxt_error("option \"-p\" requires directory name\n");
             return NXT_ERROR;
 
         case 'v':
@@ -334,8 +334,9 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
             break;
 
         default:
-            fprintf(stderr, "Unknown argument: \"%s\" "
-                    "try \"%s -h\" for available options\n", argv[i], argv[0]);
+            nxt_error("Unknown argument: \"%s\" "
+                      "try \"%s -h\" for available options\n", argv[i],
+                      argv[0]);
             return NXT_ERROR;
         }
     }
@@ -374,7 +375,7 @@ njs_externals_init(njs_vm_t *vm, njs_console_t *console)
 
     proto = njs_vm_external_prototype(vm, &njs_externals[0]);
     if (proto == NULL) {
-        fprintf(stderr, "failed to add console proto\n");
+        nxt_error("failed to add console proto\n");
         return NXT_ERROR;
     }
 
@@ -409,7 +410,7 @@ njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)
     nxt_str_t  line;
 
     if (njs_editline_init() != NXT_OK) {
-        fprintf(stderr, "failed to init completions\n");
+        nxt_error("failed to init completions\n");
         return NXT_ERROR;
     }
 
@@ -419,10 +420,10 @@ njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)
     }
 
     if (!opts->quiet) {
-        printf("interactive njs %s\n\n", NJS_VERSION);
+        nxt_printf("interactive njs %s\n\n", NJS_VERSION);
 
-        printf("v.<Tab> -> the properties and prototype methods of v.\n");
-        printf("type console.help() for more information\n\n");
+        nxt_printf("v.<Tab> -> the properties and prototype methods of v.\n");
+        nxt_printf("type console.help() for more information\n\n");
     }
 
     for ( ;; ) {
@@ -469,15 +470,15 @@ njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options)
     } else {
         fd = open(file, O_RDONLY);
         if (fd == -1) {
-            fprintf(stderr, "failed to open file: '%s' (%s)\n",
-                    file, strerror(errno));
+            nxt_error("failed to open file: '%s' (%s)\n",
+                      file, strerror(errno));
             return NXT_ERROR;
         }
     }
 
     if (fstat(fd, &sb) == -1) {
-        fprintf(stderr, "fstat(%d) failed while reading '%s' (%s)\n",
-                fd, file, strerror(errno));
+        nxt_error("fstat(%d) failed while reading '%s' (%s)\n",
+                  fd, file, strerror(errno));
         ret = NXT_ERROR;
         goto close_fd;
     }
@@ -491,7 +492,7 @@ njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options)
     script.length = 0;
     script.start = realloc(NULL, size);
     if (script.start == NULL) {
-        fprintf(stderr, "alloc failed while reading '%s'\n", file);
+        nxt_error("alloc failed while reading '%s'\n", file);
         ret = NXT_ERROR;
         goto done;
     }
@@ -507,8 +508,8 @@ njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options)
         }
 
         if (n < 0) {
-            fprintf(stderr, "failed to read file: '%s' (%s)\n",
-                    file, strerror(errno));
+            nxt_error("failed to read file: '%s' (%s)\n",
+                      file, strerror(errno));
             ret = NXT_ERROR;
             goto done;
         }
@@ -518,7 +519,7 @@ njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 
             start = realloc(script.start, size);
             if (start == NULL) {
-                fprintf(stderr, "alloc failed while reading '%s'\n", file);
+                nxt_error("alloc failed while reading '%s'\n", file);
                 ret = NXT_ERROR;
                 goto done;
             }
@@ -576,12 +577,12 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 
     vm = njs_vm_create(vm_options);
     if (vm == NULL) {
-        fprintf(stderr, "failed to create vm\n");
+        nxt_error("failed to create vm\n");
         return NULL;
     }
 
     if (njs_externals_init(vm, vm_options->external) != NXT_OK) {
-        fprintf(stderr, "failed to add external protos\n");
+        nxt_error("failed to add external protos\n");
         return NULL;
     }
 
@@ -591,7 +592,7 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 
         ret = njs_vm_add_path(vm, &path);
         if (ret != NXT_OK) {
-            fprintf(stderr, "failed to add path\n");
+            nxt_error("failed to add path\n");
             return NULL;
         }
     }
@@ -609,7 +610,7 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 
         ret = njs_vm_add_path(vm, &path);
         if (ret != NXT_OK) {
-            fprintf(stderr, "failed to add path\n");
+            nxt_error("failed to add path\n");
             return NULL;
         }
 
@@ -635,10 +636,10 @@ njs_output(njs_vm_t *vm, njs_opts_t *opts, njs_ret_t ret)
     }
 
     if (ret != NJS_OK) {
-        fprintf(stderr, "%.*s\n", (int) out.length, out.start);
+        nxt_error("%V\n", &out);
 
     } else if (opts->interactive) {
-        printf("%.*s\n", (int) out.length, out.start);
+        nxt_printf("%V\n", &out);
     }
 }
 
@@ -688,7 +689,7 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
     if (ret == NXT_OK) {
         if (opts->disassemble) {
             njs_disassembler(vm);
-            printf("\n");
+            nxt_printf("\n");
         }
 
         ret = njs_vm_start(vm);
@@ -703,7 +704,7 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
 
         ret = njs_process_events(console, opts);
         if (nxt_slow_path(ret != NXT_OK)) {
-            fprintf(stderr, "njs_process_events() failed\n");
+            nxt_error("njs_process_events() failed\n");
             ret = NJS_ERROR;
             break;
         }
@@ -711,8 +712,7 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
         if (njs_vm_waiting(vm) && !njs_vm_posted(vm)) {
             /*TODO: async events. */
 
-            fprintf(stderr, "njs_process_script(): "
-                    "async events unsupported\n");
+            nxt_error("njs_process_script(): async events unsupported\n");
             ret = NJS_ERROR;
             break;
         }
@@ -913,13 +913,13 @@ njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             return NJS_ERROR;
         }
 
-        printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start);
+        nxt_printf("%s%V", (n != 1) ? " " : "", &msg);
 
         n++;
     }
 
     if (nargs > 1) {
-        printf("\n");
+        nxt_printf("\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -944,13 +944,13 @@ njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             return NJS_ERROR;
         }
 
-        printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start);
+        nxt_printf("%s%V", (n != 1) ? " " : "", &msg);
 
         n++;
     }
 
     if (nargs > 1) {
-        printf("\n");
+        nxt_printf("\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -965,24 +965,24 @@ njs_ext_console_help(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 {
     const njs_object_init_t  *obj, **objpp;
 
-    printf("VM built-in objects:\n");
+    nxt_printf("VM built-in objects:\n");
 
     for (objpp = njs_constructor_init; *objpp != NULL; objpp++) {
         obj = *objpp;
 
-        printf("  %.*s\n", (int) obj->name.length, obj->name.start);
+        nxt_printf("  %V\n", &obj->name);
     }
 
     for (objpp = njs_object_init; *objpp != NULL; objpp++) {
         obj = *objpp;
 
-        printf("  %.*s\n", (int) obj->name.length, obj->name.start);
+        nxt_printf("  %V\n", &obj->name);
     }
 
-    printf("\nEmbedded objects:\n");
-    printf("  console\n");
+    nxt_printf("\nEmbedded objects:\n");
+    nxt_printf("  console\n");
 
-    printf("\n");
+    nxt_printf("\n");
 
     vm->retval = njs_value_undefined;
 
@@ -1040,12 +1040,12 @@ njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         ms = ns / 1000000;
         ns = ns % 1000000;
 
-        printf("default: %" PRIu64 ".%06" PRIu64 "ms\n", ms, ns);
+        nxt_printf("default: %uL.%06uLms\n", ms, ns);
 
         console->time = UINT64_MAX;
 
     } else {
-        printf("Timer \"default\" doesn’t exist.\n");
+        nxt_printf("Timer \"default\" doesn’t exist.\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -1065,7 +1065,7 @@ njs_console_set_timer(njs_external_ptr_t external, uint64_t delay,
     nxt_lvlhsh_query_t  lhq;
 
     if (delay != 0) {
-        fprintf(stderr, "njs_console_set_timer(): async timers unsupported\n");
+        nxt_error("njs_console_set_timer(): async timers unsupported\n");
         return NULL;
     }
 
@@ -1125,7 +1125,7 @@ njs_console_clear_timer(njs_external_ptr_t external, njs_host_event_t event)
 
     ret = nxt_lvlhsh_delete(&console->events, &lhq);
     if (ret != NXT_OK) {
-        fprintf(stderr, "nxt_lvlhsh_delete() failed\n");
+        nxt_error("nxt_lvlhsh_delete() failed\n");
     }
 
     nxt_mp_free(vm->mem_pool, ev);
index 8ab45598d3925892e7de44760762ddcd2ee42c39..2521a54439ca3c6c60fba755aa51dfeb13920ba9 100644 (file)
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_time.h>
 #include <string.h>
-#include <stdio.h>
 
 
 static njs_ret_t
index cc248fe3138291409bf46973f2ee93c3fe35e0e2..0f8b4ed938de29a6641b58bfdddfc70c052acf47 100644 (file)
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_regexp.h>
 #include <string.h>
-#include <stdio.h>
 
 
 
index dadeb6717cef27634b0d806c39167ce06727c93a..f15106a4d6e0ff3ed25baf5658bf028401a4bc52 100644 (file)
@@ -7,7 +7,7 @@
 #include <njs.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdio.h>
+#include <nxt_sprintf.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -34,7 +34,7 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
 
     vm = njs_vm_create(&options);
     if (vm == NULL) {
-        printf("njs_vm_create() failed\n");
+        nxt_printf("njs_vm_create() failed\n");
         goto done;
     }
 
@@ -42,7 +42,7 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
 
     ret = njs_vm_compile(vm, &start, start + script->length);
     if (ret != NXT_OK) {
-        printf("njs_vm_compile() failed\n");
+        nxt_printf("njs_vm_compile() failed\n");
         goto done;
     }
 
@@ -50,23 +50,21 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
 
         nvm = njs_vm_clone(vm, NULL);
         if (nvm == NULL) {
-            printf("njs_vm_clone() failed\n");
+            nxt_printf("njs_vm_clone() failed\n");
             goto done;
         }
 
         (void) njs_vm_start(nvm);
 
         if (njs_vm_retval_to_ext_string(nvm, &s) != NXT_OK) {
-            printf("njs_vm_retval_to_ext_string() failed\n");
+            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
             goto done;
         }
 
         success = nxt_strstr_eq(result, &s);
 
         if (!success) {
-            printf("failed: \"%.*s\" vs \"%.*s\"\n",
-                   (int) result->length, result->start, (int) s.length,
-                   s.start);
+            nxt_printf("failed: \"%V\" vs \"%V\"\n", result, &s);
             goto done;
         }
 
@@ -80,11 +78,11 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
          + usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec;
 
     if (n == 1) {
-        printf("%s: %.3fs\n", msg, (double) us / 1000000);
+        nxt_printf("%s: %.3fs\n", msg, (double) us / 1000000);
 
     } else {
-        printf("%s: %.3fµs, %d times/s\n",
-               msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us));
+        nxt_printf("%s: %.3fµs, %d times/s\n",
+                   msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us));
     }
 
     rc = NXT_OK;
@@ -170,6 +168,6 @@ main(int argc, char **argv)
         }
     }
 
-    printf("unknown agrument\n");
+    nxt_printf("unknown agrument\n");
     return EXIT_FAILURE;
 }
index af628f5d49e8bacaa3f0ff8bc694426e1207b783..192b81cc2e5c29d1e117a7c45c0e9789e69974ad 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <njs.h>
 #include <string.h>
-#include <stdio.h>
+#include <nxt_sprintf.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -273,8 +273,7 @@ njs_interactive_test(nxt_bool_t verbose)
         test = &njs_test[i];
 
         if (verbose) {
-            printf("\"%.*s\"\n", (int) test->script.length, test->script.start);
-            fflush(stdout);
+            nxt_printf("\"%V\"\n", &test->script);
         }
 
         nxt_memzero(&options, sizeof(njs_vm_opt_t));
@@ -284,7 +283,7 @@ njs_interactive_test(nxt_bool_t verbose)
 
         vm = njs_vm_create(&options);
         if (vm == NULL) {
-            printf("njs_vm_create() failed\n");
+            nxt_printf("njs_vm_create() failed\n");
             goto done;
         }
 
@@ -307,7 +306,7 @@ njs_interactive_test(nxt_bool_t verbose)
         }
 
         if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-            printf("njs_vm_retval_to_ext_string() failed\n");
+            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
             goto done;
         }
 
@@ -318,17 +317,15 @@ njs_interactive_test(nxt_bool_t verbose)
             continue;
         }
 
-        printf("njs_interactive(\"%.*s\") failed: \"%.*s\" vs \"%.*s\"\n",
-               (int) test->script.length, test->script.start,
-               (int) test->ret.length, test->ret.start,
-               (int) s.length, s.start);
+        nxt_printf("njs_interactive(\"%V\") failed: \"%V\" vs \"%V\"\n",
+                   &test->script, &test->ret, &s);
 
         goto done;
     }
 
     ret = NXT_OK;
 
-    printf("njs interactive tests passed\n");
+    nxt_printf("njs interactive tests passed\n");
 
 done:
 
index 016d2c171c15191578773dcb8c813e4f89739c10..d6f62cd27487284c699b5e0b168d043127dac319 100644 (file)
@@ -9,7 +9,6 @@
 #include <nxt_djb_hash.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdio.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -12237,7 +12236,7 @@ njs_externals_init(njs_vm_t *vm)
 
     proto = njs_vm_external_prototype(vm, &nxt_test_external[0]);
     if (proto == NULL) {
-        printf("njs_vm_external_prototype() failed\n");
+        nxt_printf("njs_vm_external_prototype() failed\n");
         return NXT_ERROR;
     }
 
@@ -12257,14 +12256,14 @@ njs_externals_init(njs_vm_t *vm)
         ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value),
                                      proto, &requests[i]);
         if (ret != NXT_OK) {
-            printf("njs_vm_external_create() failed\n");
+            nxt_printf("njs_vm_external_create() failed\n");
             return NXT_ERROR;
         }
 
         ret = njs_vm_external_bind(vm, &nxt_test_requests[i].name,
                                    njs_value_arg(&requests[i].value));
         if (ret != NXT_OK) {
-            printf("njs_vm_external_bind() failed\n");
+            nxt_printf("njs_vm_external_bind() failed\n");
             return NXT_ERROR;
         }
 
@@ -12274,13 +12273,13 @@ njs_externals_init(njs_vm_t *vm)
                                           &nxt_test_requests[i].props[j].value);
 
             if (prop == NULL) {
-                printf("lvlhsh_unit_test_alloc() failed\n");
+                nxt_printf("lvlhsh_unit_test_alloc() failed\n");
                 return NXT_ERROR;
             }
 
             ret = lvlhsh_unit_test_add(&requests[i], prop);
             if (ret != NXT_OK) {
-                printf("lvlhsh_unit_test_add() failed\n");
+                nxt_printf("lvlhsh_unit_test_add() failed\n");
                 return NXT_ERROR;
             }
         }
@@ -12310,16 +12309,14 @@ njs_unit_test(njs_unit_test_t tests[], size_t num, nxt_bool_t disassemble,
     for (i = 0; i < num; i++) {
 
         if (verbose) {
-            printf("\"%.*s\"\n",
-                   (int) njs_test[i].script.length, njs_test[i].script.start);
-            fflush(stdout);
+            nxt_printf("\"%V\"\n", &njs_test[i].script);
         }
 
         nxt_memzero(&options, sizeof(njs_vm_opt_t));
 
         vm = njs_vm_create(&options);
         if (vm == NULL) {
-            printf("njs_vm_create() failed\n");
+            nxt_printf("njs_vm_create() failed\n");
             goto done;
         }
 
@@ -12335,25 +12332,24 @@ njs_unit_test(njs_unit_test_t tests[], size_t num, nxt_bool_t disassemble,
         if (ret == NXT_OK) {
             if (disassemble) {
                 njs_disassembler(vm);
-                fflush(stdout);
             }
 
             nvm = njs_vm_clone(vm, NULL);
             if (nvm == NULL) {
-                printf("njs_vm_clone() failed\n");
+                nxt_printf("njs_vm_clone() failed\n");
                 goto done;
             }
 
             ret = njs_vm_start(nvm);
 
             if (njs_vm_retval_to_ext_string(nvm, &s) != NXT_OK) {
-                printf("njs_vm_retval_to_ext_string() failed\n");
+                nxt_printf("njs_vm_retval_to_ext_string() failed\n");
                 goto done;
             }
 
         } else {
             if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-                printf("njs_vm_retval_to_ext_string() failed\n");
+                nxt_printf("njs_vm_retval_to_ext_string() failed\n");
                 goto done;
             }
         }
@@ -12372,10 +12368,8 @@ njs_unit_test(njs_unit_test_t tests[], size_t num, nxt_bool_t disassemble,
             continue;
         }
 
-        printf("njs(\"%.*s\")\nexpected: \"%.*s\"\n     got: \"%.*s\"\n",
-               (int) njs_test[i].script.length, njs_test[i].script.start,
-               (int) njs_test[i].ret.length, njs_test[i].ret.start,
-               (int) s.length, s.start);
+        nxt_printf("njs(\"%V\")\nexpected: \"%V\"\n     got: \"%V\"\n",
+                   &njs_test[i].script, &njs_test[i].ret, &s);
 
         goto done;
     }
@@ -12591,11 +12585,9 @@ nxt_file_basename_test(njs_vm_t * vm, nxt_bool_t disassemble,
         success = nxt_strstr_eq(&tests[i].expected, &name);
 
         if (!success) {
-            printf("nxt_file_basename_test(\"%.*s\"):\n"
-                   "expected: \"%.*s\"\n     got: \"%.*s\"\n",
-                   (int) tests[i].path.length, tests[i].path.start,
-                   (int) tests[i].expected.length, tests[i].expected.start,
-                   (int) name.length, name.start);
+            nxt_printf("nxt_file_basename_test(\"%V\"):\n"
+                       "expected: \"%V\"\n     got: \"%V\"\n",
+                       &tests[i].path, &tests[i].expected, &name);
             return NXT_ERROR;
         }
     }
@@ -12637,11 +12629,9 @@ nxt_file_dirname_test(njs_vm_t * vm, nxt_bool_t disassemble,
         success = nxt_strstr_eq(&tests[i].expected, &name);
 
         if (!success) {
-            printf("nxt_file_dirname_test(\"%.*s\"):\n"
-                   "expected: \"%.*s\"\n     got: \"%.*s\"\n",
-                   (int) tests[i].path.length, tests[i].path.start,
-                   (int) tests[i].expected.length, tests[i].expected.start,
-                   (int) name.length, name.start);
+            nxt_printf("nxt_file_dirname_test(\"%V\"):\n"
+                       "expected: \"%V\"\n     got: \"%V\"\n",
+                       &tests[i].path, &tests[i].expected, &name);
             return NXT_ERROR;
         }
     }
@@ -12745,7 +12735,7 @@ main(int argc, char **argv)
         return ret;
     }
 
-    printf("njs unit tests passed\n");
+    nxt_printf("njs unit tests passed\n");
 
     /*
      * Chatham Islands NZ-CHAT time zone.
@@ -12766,10 +12756,10 @@ main(int argc, char **argv)
             return ret;
         }
 
-        printf("njs timezone tests passed\n");
+        nxt_printf("njs timezone tests passed\n");
 
     } else {
-        printf("njs timezone tests skipped, timezone is unavailable\n");
+        nxt_printf("njs timezone tests skipped, timezone is unavailable\n");
     }
 
     ret = njs_vm_json_test(disassemble, verbose);
index f8aa07f1c89dad0e750f0f39bfefbdeca562bd6f..ac3747e616d11b12ccabdcfaec639f14bc9d2ac9 100644 (file)
@@ -17,4 +17,7 @@ NXT_EXPORT int nxt_dprintf(int fd, const char *fmt, ...);
 #define nxt_printf(fmt, ...)                                                  \
     nxt_dprintf(STDOUT_FILENO, fmt, ##__VA_ARGS__)
 
+#define nxt_error(fmt, ...)                                                  \
+    nxt_dprintf(STDERR_FILENO, fmt, ##__VA_ARGS__)
+
 #endif /* _NXT_SPRINTF_H_INCLUDED_ */
index 440a7f39af2db24856342d7af30029d2e1e040d2..362853105c515e6ef420791c912028b44b6cb24b 100644 (file)
@@ -10,7 +10,6 @@
 #include <nxt_malloc.h>
 #include <nxt_sprintf.h>
 #include <nxt_trace.h>
-#include <stdio.h>
 
 
 static u_char *
index 92848895b7d5f16b6507091bdce79e6c27cae890..a44918c2741bd986459fb7402a61b3e3e60e90a4 100644 (file)
@@ -7,14 +7,13 @@
 #include <nxt_auto_config.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_sprintf.h>
 #include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_malloc.h>
 #include <nxt_lvlhsh.h>
 #include <nxt_murmur_hash.h>
 #include <nxt_mp.h>
-#include <stdio.h>
-#include <stdarg.h>
 #include <string.h>
 
 
@@ -72,8 +71,8 @@ lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto,
         return NXT_OK;
 
     case NXT_DECLINED:
-        printf("lvlhsh unit test failed: key %08lX is already in hash\n",
-               (long) key);
+        nxt_printf("lvlhsh unit test failed: key %08Xl is already in hash\n",
+                   (long) key);
         /* Fall through. */
 
     default:
@@ -100,8 +99,8 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto,
         }
     }
 
-    printf("lvlhsh unit test failed: key %08lX not found in hash\n",
-           (long) key);
+    nxt_printf("lvlhsh unit test failed: key %08Xl not found in hash\n",
+               (long) key);
 
     return NXT_ERROR;
 }
@@ -123,7 +122,7 @@ lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto,
     ret = nxt_lvlhsh_delete(lh, &lhq);
 
     if (ret != NXT_OK) {
-        printf("lvlhsh unit test failed: key %08lX not found in hash\n",
+        nxt_printf("lvlhsh unit test failed: key %08lX not found in hash\n",
                (long) key);
     }
 
@@ -170,15 +169,14 @@ lvlhsh_free(void *mem, void *p)
 static void
 lvlhsh_alert(void *mem, const char *fmt, ...)
 {
-    int      n;
+    u_char   buf[1024], *p;
     va_list  args;
-    char     buf[1024];
 
     va_start(args, fmt);
-    n = vsnprintf(buf, sizeof(buf), fmt, args);
+    p = nxt_sprintf(buf, buf + sizeof(buf), fmt, args);
     va_end(args);
 
-    (void) printf("alert: \"%.*s\"\n", n, buf);
+    (void) nxt_error("alert: \"%*s\"\n", p - buf, buf);
 }
 
 
@@ -213,7 +211,7 @@ lvlhsh_unit_test(nxt_uint_t n)
         return NXT_ERROR;
     }
 
-    printf("lvlhsh unit test started: %ld items\n", (long) n);
+    nxt_printf("lvlhsh unit test started: %l items\n", (long) n);
 
     nxt_memzero(&lh, sizeof(nxt_lvlhsh_t));
 
@@ -222,7 +220,7 @@ lvlhsh_unit_test(nxt_uint_t n)
         key = nxt_murmur_hash2(&key, sizeof(uint32_t));
 
         if (lvlhsh_unit_test_add(&lh, &lvlhsh_proto, pool, key) != NXT_OK) {
-            printf("lvlhsh add unit test failed at %ld\n", (long) i);
+            nxt_printf("lvlhsh add unit test failed at %l\n", (long) i);
             return NXT_ERROR;
         }
     }
@@ -245,8 +243,8 @@ lvlhsh_unit_test(nxt_uint_t n)
     }
 
     if (i != n) {
-        printf("lvlhsh each unit test failed at %ld of %ld\n",
-                (long) i, (long) n);
+        nxt_printf("lvlhsh each unit test failed at %l of %l\n",
+                   (long) i, (long) n);
         return NXT_ERROR;
     }
 
@@ -260,13 +258,13 @@ lvlhsh_unit_test(nxt_uint_t n)
     }
 
     if (!nxt_mp_is_empty(pool)) {
-        printf("mem cache pool is not empty\n");
+        nxt_printf("mem cache pool is not empty\n");
         return NXT_ERROR;
     }
 
     nxt_mp_destroy(pool);
 
-    printf("lvlhsh unit test passed\n");
+    nxt_printf("lvlhsh unit test passed\n");
 
     return NXT_OK;
 }
index 4285050af3f9a45867f9c6840657406f9f28bfdc..ed6dc45d1843d1f3d1539dcfa91a11eddcabd689 100644 (file)
@@ -7,10 +7,10 @@
 #include <nxt_auto_config.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_sprintf.h>
 #include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_random.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -39,17 +39,17 @@ random_unit_test(void)
         }
 
         if (nxt_random(&r) == 0x6FCAE186) {
-            printf("random unit test passed\n");
+            nxt_printf("random unit test passed\n");
 
             nxt_random_stir(&r, getpid());
 
-            printf("random unit test: 0x%08X\n", nxt_random(&r));
+            nxt_printf("random unit test: 0x%08uXD\n", nxt_random(&r));
 
             return NXT_OK;
         }
     }
 
-    printf("random unit test failed\n");
+    nxt_printf("random unit test failed\n");
 
     return NXT_ERROR;
 }
index 44bce0b154e4ac7c08c6c7cb36e20d81fc6324fa..8fd9efc7294dcc71fee957294dea2dc9d33204d0 100644 (file)
@@ -8,10 +8,10 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_stub.h>
+#include <nxt_sprintf.h>
 #include <nxt_string.h>
 #include <nxt_rbtree.h>
 #include <nxt_murmur_hash.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -39,7 +39,7 @@ rbtree_unit_test(nxt_uint_t n)
     nxt_rbtree_node_t  *node;
     nxt_rbtree_test_t  *items, *item;
 
-    printf("rbtree unit test started: %ld nodes\n", (long) n);
+    nxt_printf("rbtree unit test started: %l nodes\n", (long) n);
 
     nxt_rbtree_init(&tree, rbtree_unit_test_comparison);
 
@@ -74,7 +74,8 @@ rbtree_unit_test(nxt_uint_t n)
         node = nxt_rbtree_find(&tree, &items[i].node);
 
         if (node != (nxt_rbtree_node_t *) &items[i].node) {
-            printf("rbtree unit test failed: %08X not found\n", items[i].key);
+            nxt_printf("rbtree unit test failed: %08uXD not found\n",
+                       items[i].key);
             goto fail;
         }
     }
@@ -87,8 +88,8 @@ rbtree_unit_test(nxt_uint_t n)
         item = (nxt_rbtree_test_t *) node;
 
         if (keys[i] != item->key) {
-            printf("rbtree unit test failed: %ld: %08X %08X\n",
-                   (long) i, keys[i], item->key);
+            nxt_printf("rbtree unit test failed: %l: %08uXD %08uXD\n",
+                       (long) i, keys[i], item->key);
             goto fail;
         }
 
@@ -97,7 +98,7 @@ rbtree_unit_test(nxt_uint_t n)
     }
 
     if (i != n) {
-        printf("rbtree unit test failed: %ld\n", (long) i);
+        nxt_printf("rbtree unit test failed: %l\n", (long) i);
         goto fail;
     }
 
@@ -107,21 +108,21 @@ rbtree_unit_test(nxt_uint_t n)
     }
 
     if (!nxt_rbtree_is_empty(&tree)) {
-        printf("rbtree unit test failed: tree is not empty\n");
+        nxt_printf("rbtree unit test failed: tree is not empty\n");
         goto fail;
     }
 
     /* Check that the sentinel callback was not modified. */
 
     if (mark != tree.sentinel.right) {
-        printf("rbtree sentinel unit test failed\n");
+        nxt_printf("rbtree sentinel unit test failed\n");
         goto fail;
     }
 
     free(keys);
     free(items);
 
-    printf("rbtree unit test passed\n");
+    nxt_printf("rbtree unit test passed\n");
 
     return NXT_OK;
 
index ba8c16ae89d07c9c62bc0a0e343589e9bd456f8c..0e66262eb2bb636c54a9d7d16c481ff3718a5f81 100644 (file)
@@ -7,10 +7,10 @@
 #include <nxt_auto_config.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_sprintf.h>
 #include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
-#include <stdio.h>
 #include <string.h>
 
 
@@ -72,8 +72,8 @@ utf8_overlong(u_char *overlong, size_t len)
                 u = (u << 8) + overlong[i];
             }
 
-            printf("nxt_utf8_decode(%05Xd, %zd) failed: %05Xd, %zd\n",
-                   u, len, d, size);
+            nxt_printf("nxt_utf8_decode(%05uXD, %uz) failed: %05uXD, %uz\n",
+                       u, len, d, size);
 
             return NXT_ERROR;
         }
@@ -93,7 +93,7 @@ utf8_unit_test(nxt_uint_t start)
     nxt_uint_t    i, k, l, m;
     const u_char  *pp;
 
-    printf("utf8 unit test started\n");
+    nxt_printf("utf8 unit test started\n");
 
     /* Test valid UTF-8. */
 
@@ -102,7 +102,7 @@ utf8_unit_test(nxt_uint_t start)
         p = nxt_utf8_encode(utf8, u);
 
         if (p == NULL) {
-            printf("nxt_utf8_encode(%05Xd) failed\n", u);
+            nxt_printf("nxt_utf8_encode(%05uXD) failed\n", u);
             return NXT_ERROR;
         }
 
@@ -111,7 +111,7 @@ utf8_unit_test(nxt_uint_t start)
         d = nxt_utf8_decode(&pp, p);
 
         if (u != d) {
-            printf("nxt_utf8_decode(%05Xd) failed: %05uxD\n", u, d);
+            nxt_printf("nxt_utf8_decode(%05uXD) failed: %05uxD\n", u, d);
             return NXT_ERROR;
         }
     }
@@ -137,7 +137,8 @@ utf8_unit_test(nxt_uint_t start)
                 u = (u << 8) + utf8[i];
             }
 
-            printf("nxt_utf8_decode(%05Xd, %zd) failed: %05Xd\n", u, len, d);
+            nxt_printf("nxt_utf8_decode(%05uXD, %uz) failed: %05uXD\n",
+                       u, len, d);
             return NXT_ERROR;
         }
     }
@@ -182,11 +183,11 @@ utf8_unit_test(nxt_uint_t start)
                          nxt_length("abc абв αβγ"));
 
     if (n != 0) {
-        printf("nxt_utf8_casecmp() failed\n");
+        nxt_printf("nxt_utf8_casecmp() failed\n");
         return NXT_ERROR;
     }
 
-    printf("utf8 unit test passed\n");
+    nxt_printf("utf8 unit test passed\n");
     return NXT_OK;
 }