Deleted Added
full compact
strfmon.c (227753) strfmon.c (268569)
1/*-
2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2011 The FreeBSD Foundation
6 * All rights reserved.
7 * Portions of this software were developed by David Chisnall
8 * under sponsorship from the FreeBSD Foundation.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2011 The FreeBSD Foundation
6 * All rights reserved.
7 * Portions of this software were developed by David Chisnall
8 * under sponsorship from the FreeBSD Foundation.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/lib/libc/stdlib/strfmon.c 227753 2011-11-20 14:45:42Z theraven $");
34__FBSDID("$FreeBSD: head/lib/libc/stdlib/strfmon.c 268569 2014-07-12 15:19:30Z pfg $");
35
36#include <sys/types.h>
37#include <ctype.h>
38#include <errno.h>
39#include <limits.h>
40#include <locale.h>
41#include <monetary.h>
42#include <stdarg.h>

--- 478 unchanged lines hidden (view full) ---

521/* convert double to ASCII */
522static char *
523__format_grouped_double(double value, int *flags,
524 int left_prec, int right_prec, int pad_char) {
525
526 char *rslt;
527 char *avalue;
528 int avalue_size;
35
36#include <sys/types.h>
37#include <ctype.h>
38#include <errno.h>
39#include <limits.h>
40#include <locale.h>
41#include <monetary.h>
42#include <stdarg.h>

--- 478 unchanged lines hidden (view full) ---

521/* convert double to ASCII */
522static char *
523__format_grouped_double(double value, int *flags,
524 int left_prec, int right_prec, int pad_char) {
525
526 char *rslt;
527 char *avalue;
528 int avalue_size;
529 char fmt[32];
530
531 size_t bufsize;
532 char *bufend;
533
534 int padded;
535
536 struct lconv *lc = localeconv();
537 char *grouping;

--- 24 unchanged lines hidden (view full) ---

562 if (right_prec == CHAR_MAX) /* POSIX locale ? */
563 right_prec = 2;
564 }
565
566 if (*flags & NEED_GROUPING)
567 left_prec += get_groups(left_prec, grouping);
568
569 /* convert to string */
529
530 size_t bufsize;
531 char *bufend;
532
533 int padded;
534
535 struct lconv *lc = localeconv();
536 char *grouping;

--- 24 unchanged lines hidden (view full) ---

561 if (right_prec == CHAR_MAX) /* POSIX locale ? */
562 right_prec = 2;
563 }
564
565 if (*flags & NEED_GROUPING)
566 left_prec += get_groups(left_prec, grouping);
567
568 /* convert to string */
570 snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1,
571 right_prec);
572 avalue_size = asprintf(&avalue, fmt, value);
569 avalue_size = asprintf(&avalue, "%*.*f", left_prec + right_prec + 1,
570 right_prec, value);
573 if (avalue_size < 0)
574 return (NULL);
575
576 /* make sure that we've enough space for result string */
571 if (avalue_size < 0)
572 return (NULL);
573
574 /* make sure that we've enough space for result string */
577 bufsize = strlen(avalue)*2+1;
575 bufsize = avalue_size * 2 + 1;
578 rslt = calloc(1, bufsize);
579 if (rslt == NULL) {
580 free(avalue);
581 return (NULL);
582 }
583 bufend = rslt + bufsize - 1; /* reserve space for trailing '\0' */
584
585 /* skip spaces at beggining */

--- 58 unchanged lines hidden ---
576 rslt = calloc(1, bufsize);
577 if (rslt == NULL) {
578 free(avalue);
579 return (NULL);
580 }
581 bufend = rslt + bufsize - 1; /* reserve space for trailing '\0' */
582
583 /* skip spaces at beggining */

--- 58 unchanged lines hidden ---