1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "apr_private.h"
21 #include "apr_strings.h"
22 #include "apr_network_io.h"
23 #include "apr_portable.h"
28 #if APR_HAVE_NETINET_IN_H
29 #include <netinet/in.h>
31 #if APR_HAVE_SYS_SOCKET_H
32 #include <sys/socket.h>
34 #if APR_HAVE_ARPA_INET_H
35 #include <arpa/inet.h>
57 typedef WIDE_INT wide_int;
58 typedef unsigned WIDE_INT u_wide_int;
59 typedef apr_int64_t widest_int;
61 /* Although Tandem supports "long long" there is no unsigned variant. */
62 typedef unsigned long u_widest_int;
64 typedef apr_uint64_t u_widest_int;
68 static const char null_string[] = "(null)";
69 #define S_NULL ((char *)null_string)
72 #define FLOAT_DIGITS 6
73 #define EXPONENT_LENGTH 10
76 * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
78 * NOTICE: this is a magic number; do not decrease it
80 #define NUM_BUF_SIZE 512
83 * cvt - IEEE floating point formatting routines.
84 * Derived from UNIX V7, Copyright(C) Caldera International Inc.
88 * apr_ecvt converts to decimal
89 * the number of digits is specified by ndigit
90 * decpt is set to the position of the decimal point
91 * sign is set to 0 for positive, 1 for negative
96 /* buf must have at least NDIG bytes */
97 static char *apr_cvt(double arg, int ndigits, int *decpt, int *sign,
102 register char *p, *p1;
104 if (ndigits >= NDIG - 1)
113 arg = modf(arg, &fi);
120 while (p1 > &buf[0] && fi != 0) {
121 fj = modf(fi / 10, &fi);
122 *--p1 = (int) ((fj + .03) * 10) + '0';
125 while (p1 < &buf[NDIG])
129 while ((fj = arg * 10) < 1) {
143 while (p <= p1 && p < &buf[NDIG]) {
145 arg = modf(arg, &fj);
146 *p++ = (int) fj + '0';
148 if (p1 >= &buf[NDIG]) {
149 buf[NDIG - 1] = '\0';
172 static char *apr_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
174 return (apr_cvt(arg, ndigits, decpt, sign, 1, buf));
177 static char *apr_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
179 return (apr_cvt(arg, ndigits, decpt, sign, 0, buf));
183 * apr_gcvt - Floating output conversion to
184 * minimal length string
187 static char *apr_gcvt(double number, int ndigit, char *buf, boolean_e altform)
190 register char *p1, *p2;
194 p1 = apr_ecvt(number, ndigit, &decpt, &sign, buf1);
198 for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--)
200 if ((decpt >= 0 && decpt - ndigit > 4)
201 || (decpt < 0 && decpt < -3)) { /* use E-style */
205 for (i = 1; i < ndigit; i++)
215 *p2++ = decpt / 100 + '0';
217 *p2++ = (decpt % 100) / 10 + '0';
218 *p2++ = decpt % 10 + '0';
229 for (i = 1; i <= ndigit; i++) {
234 if (ndigit < decpt) {
235 while (ndigit++ < decpt)
240 if (p2[-1] == '.' && !altform)
247 * The INS_CHAR macro inserts a character in the buffer and writes
248 * the buffer back to disk if necessary
249 * It uses the char pointers sp and bep:
250 * sp points to the next available character in the buffer
251 * bep points to the end-of-buffer+1
252 * While using this macro, note that the nextb pointer is NOT updated.
254 * NOTE: Evaluation of the c argument should not have any side-effects
256 #define INS_CHAR(c, sp, bep, cc) \
260 vbuff->curpos = sp; \
261 if (flush_func(vbuff)) \
263 sp = vbuff->curpos; \
264 bep = vbuff->endpos; \
271 #define NUM(c) (c - '0')
273 #define STR_TO_DEC(str, num) \
275 while (apr_isdigit(*str)) \
278 num += NUM(*str++); \
282 * This macro does zero padding so that the precision
283 * requirement is satisfied. The padding is done by
284 * adding '0's to the left of the string that is going
285 * to be printed. We don't allow precision to be large
286 * enough that we continue past the start of s.
288 * NOTE: this makes use of the magic info that s is
289 * always based on num_buf with a size of NUM_BUF_SIZE.
291 #define FIX_PRECISION(adjust, precision, s, s_len) \
293 int p = precision < NUM_BUF_SIZE - 1 ? precision : NUM_BUF_SIZE - 1; \
302 * Macro that does padding. The padding is done by printing
305 #define PAD(width, len, ch) \
308 INS_CHAR(ch, sp, bep, cc); \
314 * Prefix the character ch to the string str
316 * Set the has_prefix flag
318 #define PREFIX(str, length, ch) \
325 * Convert num to its decimal format.
327 * - a pointer to a string containing the number (no sign)
328 * - len contains the length of the string
329 * - is_negative is set to TRUE or FALSE depending on the sign
330 * of the number (always set to FALSE if is_unsigned is TRUE)
332 * The caller provides a buffer for the string: that is the buf_end argument
333 * which is a pointer to the END of the buffer + 1 (i.e. if the buffer
334 * is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
336 * Note: we have 2 versions. One is used when we need to use quads
337 * (conv_10_quad), the other when we don't (conv_10). We're assuming the
340 static char *conv_10(register wide_int num, register bool_int is_unsigned,
341 register bool_int *is_negative, char *buf_end,
344 register char *p = buf_end;
345 register u_wide_int magnitude;
348 magnitude = (u_wide_int) num;
349 *is_negative = FALSE;
352 *is_negative = (num < 0);
355 * On a 2's complement machine, negating the most negative integer
356 * results in a number that cannot be represented as a signed integer.
357 * Here is what we do to obtain the number's magnitude:
358 * a. add 1 to the number
359 * b. negate it (becomes positive)
360 * c. convert it to unsigned
364 wide_int t = num + 1;
366 magnitude = ((u_wide_int) -t) + 1;
369 magnitude = (u_wide_int) num;
373 * We use a do-while loop so that we write at least 1 digit
376 register u_wide_int new_magnitude = magnitude / 10;
378 *--p = (char) (magnitude - new_magnitude * 10 + '0');
379 magnitude = new_magnitude;
387 static char *conv_10_quad(widest_int num, register bool_int is_unsigned,
388 register bool_int *is_negative, char *buf_end,
391 register char *p = buf_end;
392 u_widest_int magnitude;
395 * We see if we can use the faster non-quad version by checking the
396 * number against the largest long value it can be. If <=, we
397 * punt to the quicker version.
399 if ((num <= ULONG_MAX && is_unsigned)
400 || (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
401 return(conv_10( (wide_int)num, is_unsigned, is_negative,
405 magnitude = (u_widest_int) num;
406 *is_negative = FALSE;
409 *is_negative = (num < 0);
412 * On a 2's complement machine, negating the most negative integer
413 * results in a number that cannot be represented as a signed integer.
414 * Here is what we do to obtain the number's magnitude:
415 * a. add 1 to the number
416 * b. negate it (becomes positive)
417 * c. convert it to unsigned
421 widest_int t = num + 1;
423 magnitude = ((u_widest_int) -t) + 1;
426 magnitude = (u_widest_int) num;
430 * We use a do-while loop so that we write at least 1 digit
433 u_widest_int new_magnitude = magnitude / 10;
435 *--p = (char) (magnitude - new_magnitude * 10 + '0');
436 magnitude = new_magnitude;
446 static char *conv_in_addr(struct in_addr *ia, char *buf_end, int *len)
448 unsigned addr = ntohl(ia->s_addr);
450 bool_int is_negative;
453 p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len);
455 p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len);
457 p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len);
459 p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len);
467 static char *conv_apr_sockaddr(apr_sockaddr_t *sa, char *buf_end, int *len)
470 bool_int is_negative;
474 p = conv_10(sa->port, TRUE, &is_negative, p, &sub_len);
476 apr_sockaddr_ip_get(&ipaddr_str, sa);
477 sub_len = strlen(ipaddr_str);
479 if (sa->family == APR_INET6 &&
480 !IN6_IS_ADDR_V4MAPPED(&sa->sa.sin6.sin6_addr)) {
484 memcpy(p + 1, ipaddr_str, sub_len);
490 memcpy(p, ipaddr_str, sub_len);
500 static char *conv_os_thread_t(apr_os_thread_t *tid, char *buf_end, int *len)
504 apr_uint64_t alignme;
509 switch(sizeof(u.tid)) {
510 case sizeof(apr_int32_t):
511 return conv_10(*(apr_uint32_t *)&u.tid, TRUE, &is_negative, buf_end, len);
512 case sizeof(apr_int64_t):
513 return conv_10_quad(*(apr_uint64_t *)&u.tid, TRUE, &is_negative, buf_end, len);
515 /* not implemented; stick 0 in the buffer */
516 return conv_10(0, TRUE, &is_negative, buf_end, len);
524 * Convert a floating point number to a string formats 'f', 'e' or 'E'.
525 * The result is placed in buf, and len denotes the length of the string
526 * The sign is returned in the is_negative argument (and is not placed
529 static char *conv_fp(register char format, register double num,
530 boolean_e add_dp, int precision, bool_int *is_negative,
533 register char *s = buf;
539 p = apr_fcvt(num, precision, &decimal_point, is_negative, buf1);
540 else /* either e or E format */
541 p = apr_ecvt(num, precision + 1, &decimal_point, is_negative, buf1);
544 * Check for Infinity and NaN
546 if (apr_isalpha(*p)) {
548 memcpy(buf, p, *len + 1);
549 *is_negative = FALSE;
554 if (decimal_point <= 0) {
558 while (decimal_point++ < 0)
565 while (decimal_point-- > 0)
567 if (precision > 0 || add_dp)
573 if (precision > 0 || add_dp)
578 * copy the rest of p, the NUL is NOT copied
584 char temp[EXPONENT_LENGTH]; /* for exponent conversion */
586 bool_int exponent_is_negative;
588 *s++ = format; /* either e or E */
590 if (decimal_point != 0) {
591 p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative,
592 &temp[EXPONENT_LENGTH], &t_len);
593 *s++ = exponent_is_negative ? '-' : '+';
596 * Make sure the exponent has at least 2 digits
616 * Convert num to a base X number where X is a power of 2. nbits determines X.
617 * For example, if nbits is 3, we do base 8 conversion
619 * a pointer to a string containing the number
621 * The caller provides a buffer for the string: that is the buf_end argument
622 * which is a pointer to the END of the buffer + 1 (i.e. if the buffer
623 * is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
625 * As with conv_10, we have a faster version which is used when
626 * the number isn't quad size.
628 static char *conv_p2(register u_wide_int num, register int nbits,
629 char format, char *buf_end, register int *len)
631 register int mask = (1 << nbits) - 1;
632 register char *p = buf_end;
633 static const char low_digits[] = "0123456789abcdef";
634 static const char upper_digits[] = "0123456789ABCDEF";
635 register const char *digits = (format == 'X') ? upper_digits : low_digits;
638 *--p = digits[num & mask];
647 static char *conv_p2_quad(u_widest_int num, register int nbits,
648 char format, char *buf_end, register int *len)
650 register int mask = (1 << nbits) - 1;
651 register char *p = buf_end;
652 static const char low_digits[] = "0123456789abcdef";
653 static const char upper_digits[] = "0123456789ABCDEF";
654 register const char *digits = (format == 'X') ? upper_digits : low_digits;
656 if (num <= ULONG_MAX)
657 return(conv_p2((u_wide_int)num, nbits, format, buf_end, len));
660 *--p = digits[num & mask];
671 * Do format conversion placing the output in buffer
673 APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *),
674 apr_vformatter_buff_t *vbuff, const char *fmt, va_list ap)
681 register char *s = NULL;
685 register int min_width = 0;
694 widest_int i_quad = (widest_int) 0;
695 u_widest_int ui_quad;
696 wide_int i_num = (wide_int) 0;
699 char num_buf[NUM_BUF_SIZE];
700 char char_buf[2]; /* for printing %% and %<unknown> */
703 IS_QUAD, IS_LONG, IS_SHORT, IS_INT
705 enum var_type_enum var_type = IS_INT;
710 boolean_e alternate_form;
711 boolean_e print_sign;
712 boolean_e print_blank;
713 boolean_e adjust_precision;
714 boolean_e adjust_width;
715 bool_int is_negative;
722 INS_CHAR(*fmt, sp, bep, cc);
726 * Default variable settings
728 boolean_e print_something = YES;
730 alternate_form = print_sign = print_blank = NO;
737 * Try to avoid checking for flags, width or precision
739 if (!apr_islower(*fmt)) {
741 * Recognize flags: -, #, BLANK, +
746 else if (*fmt == '+')
748 else if (*fmt == '#')
749 alternate_form = YES;
750 else if (*fmt == ' ')
752 else if (*fmt == '0')
759 * Check if a width was specified
761 if (apr_isdigit(*fmt)) {
762 STR_TO_DEC(fmt, min_width);
765 else if (*fmt == '*') {
766 min_width = va_arg(ap, int);
771 min_width = -min_width;
778 * Check if a precision was specified
781 adjust_precision = YES;
783 if (apr_isdigit(*fmt)) {
784 STR_TO_DEC(fmt, precision);
786 else if (*fmt == '*') {
787 precision = va_arg(ap, int);
796 adjust_precision = NO;
799 adjust_precision = adjust_width = NO;
804 #if defined(APR_INT64_T_FMT_LEN) && (APR_INT64_T_FMT_LEN == 3)
805 if ((*fmt == APR_INT64_T_FMT[0]) &&
806 (fmt[1] == APR_INT64_T_FMT[1])) {
807 #elif defined(APR_INT64_T_FMT_LEN) && (APR_INT64_T_FMT_LEN == 2)
808 if (*fmt == APR_INT64_T_FMT[0]) {
810 if (strncmp(fmt, APR_INT64_T_FMT,
811 sizeof(APR_INT64_T_FMT) - 2) == 0) {
813 /* Need to account for trailing 'd' and null in sizeof() */
815 fmt += (sizeof(APR_INT64_T_FMT) - 2);
817 else if (*fmt == 'q') {
821 else if (*fmt == 'l') {
825 else if (*fmt == 'h') {
834 * Argument extraction and printing.
835 * First we determine the argument type.
836 * Then, we convert the argument to a string.
837 * On exit from the switch, s points to the string that
838 * must be printed, s_len has the length of the string
839 * The precision requirements, if any, are reflected in s_len.
841 * NOTE: pad_char may be set to '0' because of the 0 flag.
842 * It is reset to ' ' by non-numeric formats
846 if (var_type == IS_QUAD) {
847 i_quad = va_arg(ap, u_widest_int);
848 s = conv_10_quad(i_quad, 1, &is_negative,
849 &num_buf[NUM_BUF_SIZE], &s_len);
852 if (var_type == IS_LONG)
853 i_num = (wide_int) va_arg(ap, u_wide_int);
854 else if (var_type == IS_SHORT)
855 i_num = (wide_int) (unsigned short) va_arg(ap, unsigned int);
857 i_num = (wide_int) va_arg(ap, unsigned int);
858 s = conv_10(i_num, 1, &is_negative,
859 &num_buf[NUM_BUF_SIZE], &s_len);
861 FIX_PRECISION(adjust_precision, precision, s, s_len);
866 if (var_type == IS_QUAD) {
867 i_quad = va_arg(ap, widest_int);
868 s = conv_10_quad(i_quad, 0, &is_negative,
869 &num_buf[NUM_BUF_SIZE], &s_len);
872 if (var_type == IS_LONG)
873 i_num = (wide_int) va_arg(ap, wide_int);
874 else if (var_type == IS_SHORT)
875 i_num = (wide_int) (short) va_arg(ap, int);
877 i_num = (wide_int) va_arg(ap, int);
878 s = conv_10(i_num, 0, &is_negative,
879 &num_buf[NUM_BUF_SIZE], &s_len);
881 FIX_PRECISION(adjust_precision, precision, s, s_len);
887 else if (print_blank)
893 if (var_type == IS_QUAD) {
894 ui_quad = va_arg(ap, u_widest_int);
895 s = conv_p2_quad(ui_quad, 3, *fmt,
896 &num_buf[NUM_BUF_SIZE], &s_len);
899 if (var_type == IS_LONG)
900 ui_num = (u_wide_int) va_arg(ap, u_wide_int);
901 else if (var_type == IS_SHORT)
902 ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
904 ui_num = (u_wide_int) va_arg(ap, unsigned int);
905 s = conv_p2(ui_num, 3, *fmt,
906 &num_buf[NUM_BUF_SIZE], &s_len);
908 FIX_PRECISION(adjust_precision, precision, s, s_len);
909 if (alternate_form && *s != '0') {
918 if (var_type == IS_QUAD) {
919 ui_quad = va_arg(ap, u_widest_int);
920 s = conv_p2_quad(ui_quad, 4, *fmt,
921 &num_buf[NUM_BUF_SIZE], &s_len);
924 if (var_type == IS_LONG)
925 ui_num = (u_wide_int) va_arg(ap, u_wide_int);
926 else if (var_type == IS_SHORT)
927 ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
929 ui_num = (u_wide_int) va_arg(ap, unsigned int);
930 s = conv_p2(ui_num, 4, *fmt,
931 &num_buf[NUM_BUF_SIZE], &s_len);
933 FIX_PRECISION(adjust_precision, precision, s, s_len);
934 if (alternate_form && i_num != 0) {
935 *--s = *fmt; /* 'x' or 'X' */
943 s = va_arg(ap, char *);
945 if (!adjust_precision) {
949 /* From the C library standard in section 7.9.6.1:
950 * ...if the precision is specified, no more then
951 * that many characters are written. If the
952 * precision is not specified or is greater
953 * than the size of the array, the array shall
954 * contain a null character.
956 * My reading is is precision is specified and
957 * is less then or equal to the size of the
958 * array, no null character is required. So
959 * we can't do a strlen.
961 * This figures out the length of the string
962 * up to the precision. Once it's long enough
963 * for the specified precision, we don't care
966 * NOTE: you must do the length comparison
967 * before the check for the null character.
968 * Otherwise, you'll check one beyond the
969 * last valid character.
973 for (walk = s, s_len = 0;
974 (s_len < precision) && (*walk != '\0');
989 fp_num = va_arg(ap, double);
991 * We use &num_buf[ 1 ], so that we have room for the sign
1001 if (!s && isinf(fp_num)) {
1007 s = conv_fp(*fmt, fp_num, alternate_form,
1008 (adjust_precision == NO) ? FLOAT_DIGITS : precision,
1009 &is_negative, &num_buf[1], &s_len);
1012 else if (print_sign)
1014 else if (print_blank)
1022 if (adjust_precision == NO)
1023 precision = FLOAT_DIGITS;
1024 else if (precision == 0)
1027 * * We use &num_buf[ 1 ], so that we have room for the sign
1029 s = apr_gcvt(va_arg(ap, double), precision, &num_buf[1],
1033 else if (print_sign)
1035 else if (print_blank)
1040 if (alternate_form && (q = strchr(s, '.')) == NULL) {
1042 s[s_len] = '\0'; /* delimit for following strchr() */
1044 if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL)
1050 char_buf[0] = (char) (va_arg(ap, int));
1066 if (var_type == IS_QUAD)
1067 *(va_arg(ap, widest_int *)) = cc;
1068 else if (var_type == IS_LONG)
1069 *(va_arg(ap, long *)) = cc;
1070 else if (var_type == IS_SHORT)
1071 *(va_arg(ap, short *)) = cc;
1073 *(va_arg(ap, int *)) = cc;
1074 print_something = NO;
1078 * This is where we extend the printf format, with a second
1084 * If the pointer size is equal to or smaller than the size
1085 * of the largest unsigned int, we convert the pointer to a
1086 * hex number, otherwise we print "%p" to indicate that we
1087 * don't handle "%p".
1090 #if APR_SIZEOF_VOIDP == 8
1091 if (sizeof(void *) <= sizeof(u_widest_int)) {
1092 ui_quad = (u_widest_int) va_arg(ap, void *);
1093 s = conv_p2_quad(ui_quad, 4, 'x',
1094 &num_buf[NUM_BUF_SIZE], &s_len);
1097 if (sizeof(void *) <= sizeof(u_wide_int)) {
1098 ui_num = (u_wide_int) va_arg(ap, void *);
1099 s = conv_p2(ui_num, 4, 'x',
1100 &num_buf[NUM_BUF_SIZE], &s_len);
1111 /* print an apr_sockaddr_t as a.b.c.d:port */
1116 sa = va_arg(ap, apr_sockaddr_t *);
1118 s = conv_apr_sockaddr(sa, &num_buf[NUM_BUF_SIZE], &s_len);
1119 if (adjust_precision && precision < s_len)
1130 /* print a struct in_addr as a.b.c.d */
1135 ia = va_arg(ap, struct in_addr *);
1137 s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len);
1138 if (adjust_precision && precision < s_len)
1152 apr_os_thread_t *tid;
1154 tid = va_arg(ap, apr_os_thread_t *);
1156 s = conv_os_thread_t(tid, &num_buf[NUM_BUF_SIZE], &s_len);
1157 if (adjust_precision && precision < s_len)
1175 /* if %p ends the string, oh well ignore it */
1182 (void)va_arg(ap, void *); /* skip the bogus argument on the stack */
1189 * The last character of the format string was %.
1196 * The default case is for unrecognized %'s.
1197 * We print %<char> to help the user identify what
1198 * option is not understood.
1199 * This is also useful in case the user wants to pass
1200 * the output of format_converter to another function
1201 * that understands some other %<char> (like syslog).
1202 * Note that we can't point s inside fmt because the
1203 * unknown <char> could be preceded by width etc.
1214 if (prefix_char != NUL && s != S_NULL && s != char_buf) {
1219 if (adjust_width && adjust == RIGHT && min_width > s_len) {
1220 if (pad_char == '0' && prefix_char != NUL) {
1221 INS_CHAR(*s, sp, bep, cc);
1226 PAD(min_width, s_len, pad_char);
1230 * Print the string s.
1232 if (print_something == YES) {
1233 for (i = s_len; i != 0; i--) {
1234 INS_CHAR(*s, sp, bep, cc);
1239 if (adjust_width && adjust == LEFT && min_width > s_len)
1240 PAD(min_width, s_len, pad_char);
1250 static int snprintf_flush(apr_vformatter_buff_t *vbuff)
1252 /* if the buffer fills we have to abort immediately, there is no way
1253 * to "flush" an apr_snprintf... there's nowhere to flush it to.
1259 APR_DECLARE_NONSTD(int) apr_snprintf(char *buf, apr_size_t len,
1260 const char *format, ...)
1264 apr_vformatter_buff_t vbuff;
1267 /* NOTE: This is a special case; we just want to return the number
1268 * of chars that would be written (minus \0) if the buffer
1269 * size was infinite. We leverage the fact that INS_CHAR
1270 * just does actual inserts iff the buffer pointer is non-NULL.
1271 * In this case, we don't care what buf is; it can be NULL, since
1272 * we don't touch it at all.
1274 vbuff.curpos = NULL;
1275 vbuff.endpos = NULL;
1277 /* save one byte for nul terminator */
1279 vbuff.endpos = buf + len - 1;
1281 va_start(ap, format);
1282 cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
1285 *vbuff.curpos = '\0';
1287 return (cc == -1) ? (int)len : cc;
1291 APR_DECLARE(int) apr_vsnprintf(char *buf, apr_size_t len, const char *format,
1295 apr_vformatter_buff_t vbuff;
1298 /* See above note */
1299 vbuff.curpos = NULL;
1300 vbuff.endpos = NULL;
1302 /* save one byte for nul terminator */
1304 vbuff.endpos = buf + len - 1;
1306 cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
1308 *vbuff.curpos = '\0';
1310 return (cc == -1) ? (int)len : cc;