Mercurial > njs
changeset 878:b9d619068453
Allowing to output large values in console.log().
Previously, the size was limited to 2048 bytes.
This closes #127 issue on Github.
| author | Dmitry Volyntsev <xeioex@nginx.com> |
|---|---|
| date | Thu, 11 Apr 2019 16:32:06 +0300 |
| parents | 0c8a6246a4af |
| children | 4df50ca085e7 |
| files | njs/njs_shell.c nxt/nxt_sprintf.c nxt/nxt_sprintf.h |
| diffstat | 3 files changed, 35 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/njs/njs_shell.c Thu Apr 11 15:00:17 2019 +0300 +++ b/njs/njs_shell.c Thu Apr 11 16:32:06 2019 +0300 @@ -645,7 +645,8 @@ nxt_error("%V\n", &out); } else if (opts->interactive) { - nxt_printf("%V\n", &out); + nxt_print(out.start, out.length); + nxt_printf("\n"); } } @@ -919,7 +920,8 @@ return NJS_ERROR; } - nxt_printf("%s%V", (n != 1) ? " " : "", &msg); + nxt_printf("%s", (n != 1) ? " " : ""); + nxt_print(msg.start, msg.length); n++; } @@ -950,7 +952,8 @@ return NJS_ERROR; } - nxt_printf("%s%V", (n != 1) ? " " : "", &msg); + nxt_printf("%s", (n != 1) ? " " : ""); + nxt_print(msg.start, msg.length); n++; }
--- a/nxt/nxt_sprintf.c Thu Apr 11 15:00:17 2019 +0300 +++ b/nxt/nxt_sprintf.c Thu Apr 11 16:32:06 2019 +0300 @@ -64,23 +64,6 @@ } -int -nxt_dprintf(int fd, const char *fmt, ...) -{ - size_t size; - u_char text[2048], *p; - va_list args; - - va_start(args, fmt); - p = nxt_vsprintf(text, text + sizeof(text), fmt, args); - va_end(args); - - size = p - text; - - return write(fd, text, size); -} - - /* * nxt_sprintf_t is used: * to pass several parameters of nxt_integer() via single pointer @@ -602,3 +585,27 @@ return buf; } + + +NXT_EXPORT +int nxt_dprint(int fd, u_char *buf, size_t size) +{ + return write(fd, buf, size); +} + + +int +nxt_dprintf(int fd, const char *fmt, ...) +{ + size_t size; + u_char text[2048], *p; + va_list args; + + va_start(args, fmt); + p = nxt_vsprintf(text, text + sizeof(text), fmt, args); + va_end(args); + + size = p - text; + + return write(fd, text, size); +}
--- a/nxt/nxt_sprintf.h Thu Apr 11 15:00:17 2019 +0300 +++ b/nxt/nxt_sprintf.h Thu Apr 11 16:32:06 2019 +0300 @@ -12,9 +12,13 @@ NXT_EXPORT u_char *nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args); +NXT_EXPORT int nxt_dprint(int fd, u_char *buf, size_t size); NXT_EXPORT int nxt_dprintf(int fd, const char *fmt, ...); -#define nxt_printf(fmt, ...) \ +#define nxt_print(buf, size) \ + nxt_dprint(STDOUT_FILENO, (u_char *) buf, size) + +#define nxt_printf(fmt, ...) \ nxt_dprintf(STDOUT_FILENO, fmt, ##__VA_ARGS__) #define nxt_error(fmt, ...) \
