summaryrefslogtreecommitdiff
path: root/main/spprintf.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-12-18 17:53:27 +0100
committerNikita Popov <nikic@php.net>2017-01-01 21:28:20 +0100
commit5fc9aa9a9509727a55ec5badae9df1a9617be6a1 (patch)
tree1ffcd5cf9baee362c5556d4e5bf99e973cb255fe /main/spprintf.c
parentc7742e280a4edcc8b216d7b798c805c9a439d663 (diff)
downloadphp-git-5fc9aa9a9509727a55ec5badae9df1a9617be6a1.tar.gz
Make printf_to_smart_str(ing) the primitive printf operation
vs(tr)pprintf is now implemented in Zend on top of printf_to_smart_str(int), which is provided as a utility function. This allows us to efficiently printf to the end of a smart string.
Diffstat (limited to 'main/spprintf.c')
-rw-r--r--main/spprintf.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/main/spprintf.c b/main/spprintf.c
index 8f141c9978..0e0784663c 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -827,52 +827,15 @@ skip_output:
}
/* }}} */
-/*
- * This is the general purpose conversion function.
- */
-PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
+PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap) /* {{{ */
{
- smart_string buf = {0};
-
- /* since there are places where (v)spprintf called without checking for null,
- a bit of defensive coding here */
- if(!pbuf) {
- return 0;
- }
- xbuf_format_converter(&buf, 1, format, ap);
-
- if (max_len && buf.len > max_len) {
- buf.len = max_len;
- }
-
- smart_string_0(&buf);
-
- if (buf.c) {
- *pbuf = buf.c;
- return buf.len;
- } else {
- *pbuf = estrndup("", 0);
- return 0;
- }
+ xbuf_format_converter(buf, 1, format, ap);
}
/* }}} */
-PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
+PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap) /* {{{ */
{
- smart_str buf = {0};
-
- xbuf_format_converter(&buf, 0, format, ap);
-
- if (!buf.s) {
- return ZSTR_EMPTY_ALLOC();
- }
-
- if (max_len && ZSTR_LEN(buf.s) > max_len) {
- ZSTR_LEN(buf.s) = max_len;
- }
-
- smart_str_0(&buf);
- return buf.s;
+ xbuf_format_converter(buf, 0, format, ap);
}
/* }}} */