summaryrefslogtreecommitdiff
path: root/main/snprintf.h
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2007-02-24 18:20:46 +0000
committerMarcus Boerger <helly@php.net>2007-02-24 18:20:46 +0000
commit1345740fa5fbfce210d0c68d1f032b26d6973236 (patch)
treec673e0fccb6bd014a4bab580fa483101433c6634 /main/snprintf.h
parent3588f9eed61804ab475ae2ed5c4160d92590e771 (diff)
downloadphp-git-1345740fa5fbfce210d0c68d1f032b26d6973236.tar.gz
- Add [v]slprintf to overcome the returnvalues issue of snprintf
Diffstat (limited to 'main/snprintf.h')
-rw-r--r--main/snprintf.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/main/snprintf.h b/main/snprintf.h
index 8e66c458ba..ef6757d166 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -21,7 +21,7 @@
/*
-Comparing: sprintf, snprintf, spprintf
+Comparing: sprintf, snprintf, slprintf, spprintf
sprintf offers the ability to make a lot of failures since it does not know
the size of the buffer it uses. Therefore usage of sprintf often
@@ -36,6 +36,11 @@ snprintf knows the buffers size and will not write behind it. But you will
A bad thing is having a big maximum while in most cases you would
only need a small buffer. If the size of the resulting string is
longer or equal to the buffer size than the buffer is not terminated.
+ The function also returns the number of chars not including the
+ terminating \0 that were needed to fully comply to the print request.
+
+slprintf same as snprintf with the difference that it actually returns the
+ length printed not including the terminating \0.
spprintf is the dynamical version of snprintf. It allocates the buffer in size
as needed and allows a maximum setting as snprintf (turn this feature
@@ -73,6 +78,8 @@ typedef enum {
BEGIN_EXTERN_C()
+PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
PHPAPI int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
@@ -82,6 +89,16 @@ PHPAPI char * php_conv_fp(register char format, register double num,
END_EXTERN_C()
+#ifdef slprintf
+#undef slprintf
+#endif
+#define slprintf ap_php_slprintf
+
+#ifdef vslprintf
+#undef vslprintf
+#endif
+#define vslprintf ap_php_vslprintf
+
#ifdef snprintf
#undef snprintf
#endif