[njs] Added nxt_dprintf() and nxt_printf().

Dmitry Volyntsev xeioex at nginx.com
Wed Mar 27 18:11:02 UTC 2019


details:   https://hg.nginx.org/njs/rev/65ec3b20de81
branches:  
changeset: 853:65ec3b20de81
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Mar 27 21:00:19 2019 +0300
description:
Added nxt_dprintf() and nxt_printf().

diffstat:

 nxt/nxt_sprintf.c |  17 +++++++++++++++++
 nxt/nxt_sprintf.h |   4 ++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diffs (40 lines):

diff -r 27347fbb3d0a -r 65ec3b20de81 nxt/nxt_sprintf.c
--- a/nxt/nxt_sprintf.c	Wed Mar 27 21:00:19 2019 +0300
+++ b/nxt/nxt_sprintf.c	Wed Mar 27 21:00:19 2019 +0300
@@ -64,6 +64,23 @@ nxt_sprintf(u_char *buf, u_char *end, co
 }
 
 
+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
diff -r 27347fbb3d0a -r 65ec3b20de81 nxt/nxt_sprintf.h
--- a/nxt/nxt_sprintf.h	Wed Mar 27 21:00:19 2019 +0300
+++ b/nxt/nxt_sprintf.h	Wed Mar 27 21:00:19 2019 +0300
@@ -12,5 +12,9 @@ NXT_EXPORT u_char *nxt_sprintf(u_char *b
 NXT_EXPORT u_char *nxt_vsprintf(u_char *buf, u_char *end, const char *fmt,
     va_list args);
 
+NXT_EXPORT int nxt_dprintf(int fd, const char *fmt, ...);
+
+#define nxt_printf(fmt, ...)                                                  \
+    nxt_dprintf(STDOUT_FILENO, fmt, ##__VA_ARGS__)
 
 #endif /* _NXT_SPRINTF_H_INCLUDED_ */


More information about the nginx-devel mailing list