aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/os/xprintf.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-05-10 11:49:54 +0200
committermarha <marha@users.sourceforge.net>2012-05-10 11:49:54 +0200
commit6231dd66fec697922b164ec03731f04542c2b30e (patch)
tree83bfa2dec8ba2d32860d513b7816dae412712fa5 /xorg-server/os/xprintf.c
parent58780b4306bd1254c6c0e65d255630d5c546005f (diff)
parent13a63d4f69c0692539448cb3d8e4a0e1ffdf2183 (diff)
downloadvcxsrv-6231dd66fec697922b164ec03731f04542c2b30e.tar.gz
vcxsrv-6231dd66fec697922b164ec03731f04542c2b30e.tar.bz2
vcxsrv-6231dd66fec697922b164ec03731f04542c2b30e.zip
Merge remote-tracking branch 'origin/released'
Conflicts: xorg-server/os/log.c
Diffstat (limited to 'xorg-server/os/xprintf.c')
-rw-r--r--xorg-server/os/xprintf.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/xorg-server/os/xprintf.c b/xorg-server/os/xprintf.c
index 226e68c2b..58aad894b 100644
--- a/xorg-server/os/xprintf.c
+++ b/xorg-server/os/xprintf.c
@@ -193,6 +193,50 @@ XNFasprintf(char **ret, const char *_X_RESTRICT_KYWD format, ...)
return size;
}
+/**
+ * Varargs snprintf that returns the actual number of bytes (excluding final
+ * '\0') that were copied into the buffer.
+ * This is opposed to the normal sprintf() usually returns the number of bytes
+ * that would have been written.
+ *
+ * @param s buffer to copy into
+ * @param n size of buffer s
+ * @param format printf style format string
+ * @param va variable argument list
+ * @return number of bytes actually copied, excluding final '\0'
+ */
+int
+Xvscnprintf(char *s, int n, const char *format, va_list args)
+{
+ int x;
+ if (n == 0)
+ return 0;
+ x = vsnprintf(s, n , format, args);
+ return (x >= n) ? (n - 1) : x;
+}
+
+/**
+ * snprintf that returns the actual number of bytes (excluding final '\0') that
+ * were copied into the buffer.
+ * This is opposed to the normal sprintf() usually returns the number of bytes
+ * that would have been written.
+ *
+ * @param s buffer to copy into
+ * @param n size of buffer s
+ * @param format printf style format string
+ * @param ... arguments for specified format
+ * @return number of bytes actually copied, excluding final '\0'
+ */
+int Xscnprintf(char *s, int n, const char *format, ...)
+{
+ int x;
+ va_list ap;
+ va_start(ap, format);
+ x = Xvscnprintf(s, n, format, ap);
+ va_end(ap);
+ return x;
+}
+
/* Old api, now deprecated, may be removed in the future */
char *
Xvprintf(const char *format, va_list va)