1 /* Internal function for converting integers to ASCII.
2 Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 /* When long long is different from long, by default, _itoa_word is
25 provided to convert long to ASCII and _itoa is provided to convert
26 long long. A sysdeps _itoa.h can define _ITOA_NEEDED to 0 and define
27 _ITOA_WORD_TYPE to unsigned long long int to override it so that
28 _itoa_word is changed to convert long long to ASCII and _itoa is
29 mapped to _itoa_word. */
32 # define _ITOA_NEEDED (LONG_MAX != LLONG_MAX)
34 #ifndef _ITOA_WORD_TYPE
35 # define _ITOA_WORD_TYPE unsigned long int
39 /* Convert VALUE into ASCII in base BASE (2..36).
40 Write backwards starting the character just before BUFLIM.
41 Return the address of the first (left-to-right) character in the number.
42 Use upper case letters iff UPPER_CASE is nonzero. */
44 extern char *_itoa (unsigned long long int value
, char *buflim
,
45 unsigned int base
, int upper_case
) attribute_hidden
;
47 extern const char _itoa_upper_digits
[];
48 extern const char _itoa_lower_digits
[];
49 #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
50 hidden_proto (_itoa_upper_digits
)
51 hidden_proto (_itoa_lower_digits
)
55 extern char *_itoa_word (_ITOA_WORD_TYPE value
, char *buflim
,
57 int upper_case
) attribute_hidden
;
59 static inline char * __attribute__ ((unused
, always_inline
))
60 _itoa_word (_ITOA_WORD_TYPE value
, char *buflim
,
61 unsigned int base
, int upper_case
)
63 const char *digits
= (upper_case
65 : _itoa_lower_digits
);
69 # define SPECIAL(Base) \
72 *--buflim = digits[value % Base]; \
73 while ((value /= Base) != 0); \
81 *--buflim
= digits
[value
% base
];
82 while ((value
/= base
) != 0);
89 /* Similar to the _itoa functions, but output starts at buf and pointer
90 after the last written character is returned. */
91 extern char *_fitoa_word (_ITOA_WORD_TYPE value
, char *buf
,
93 int upper_case
) attribute_hidden
;
94 extern char *_fitoa (unsigned long long value
, char *buf
, unsigned int base
,
95 int upper_case
) attribute_hidden
;
98 /* No need for special long long versions. */
99 # define _itoa(value, buf, base, upper_case) \
100 _itoa_word (value, buf, base, upper_case)
101 # define _fitoa(value, buf, base, upper_case) \
102 _fitoa_word (value, buf, base, upper_case)