Blame sysdeps/generic/_itoa.h

Packit 6c4009
/* Internal function for converting integers to ASCII.
Packit 6c4009
   Copyright (C) 1994-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _ITOA_H
Packit 6c4009
#define _ITOA_H
Packit 6c4009
Packit 6c4009
#include <limits.h>
Packit 6c4009
Packit 6c4009
/* When long long is different from long, by default, _itoa_word is
Packit 6c4009
   provided to convert long to ASCII and _itoa is provided to convert
Packit 6c4009
   long long.  A sysdeps _itoa.h can define _ITOA_NEEDED to 0 and define
Packit 6c4009
   _ITOA_WORD_TYPE to unsigned long long int to override it so that
Packit 6c4009
   _itoa_word is changed to convert long long to ASCII and _itoa is
Packit 6c4009
   mapped to _itoa_word.  */
Packit 6c4009
Packit 6c4009
#ifndef _ITOA_NEEDED
Packit 6c4009
# define _ITOA_NEEDED		(LONG_MAX != LLONG_MAX)
Packit 6c4009
#endif
Packit 6c4009
#ifndef _ITOA_WORD_TYPE
Packit 6c4009
# define _ITOA_WORD_TYPE	unsigned long int
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Convert VALUE into ASCII in base BASE (2..36).
Packit 6c4009
   Write backwards starting the character just before BUFLIM.
Packit 6c4009
   Return the address of the first (left-to-right) character in the number.
Packit 6c4009
   Use upper case letters iff UPPER_CASE is nonzero.  */
Packit 6c4009
Packit 6c4009
extern char *_itoa (unsigned long long int value, char *buflim,
Packit 6c4009
		    unsigned int base, int upper_case) attribute_hidden;
Packit 6c4009
Packit 6c4009
extern const char _itoa_upper_digits[];
Packit 6c4009
extern const char _itoa_lower_digits[];
Packit 6c4009
#if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
Packit 6c4009
hidden_proto (_itoa_upper_digits)
Packit 6c4009
hidden_proto (_itoa_lower_digits)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if IS_IN (libc)
Packit 6c4009
extern char *_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
Packit 6c4009
			 unsigned int base,
Packit 6c4009
			 int upper_case) attribute_hidden;
Packit 6c4009
#else
Packit 6c4009
static inline char * __attribute__ ((unused, always_inline))
Packit 6c4009
_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
Packit 6c4009
	    unsigned int base, int upper_case)
Packit 6c4009
{
Packit 6c4009
  const char *digits = (upper_case
Packit 6c4009
			? _itoa_upper_digits
Packit 6c4009
			: _itoa_lower_digits);
Packit 6c4009
Packit 6c4009
  switch (base)
Packit 6c4009
    {
Packit 6c4009
# define SPECIAL(Base)							      \
Packit 6c4009
    case Base:								      \
Packit 6c4009
      do								      \
Packit 6c4009
	*--buflim = digits[value % Base];				      \
Packit 6c4009
      while ((value /= Base) != 0);					      \
Packit 6c4009
      break
Packit 6c4009
Packit 6c4009
      SPECIAL (10);
Packit 6c4009
      SPECIAL (16);
Packit 6c4009
      SPECIAL (8);
Packit 6c4009
    default:
Packit 6c4009
      do
Packit 6c4009
	*--buflim = digits[value % base];
Packit 6c4009
      while ((value /= base) != 0);
Packit 6c4009
    }
Packit 6c4009
  return buflim;
Packit 6c4009
}
Packit 6c4009
# undef SPECIAL
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Similar to the _itoa functions, but output starts at buf and pointer
Packit 6c4009
   after the last written character is returned.  */
Packit 6c4009
extern char *_fitoa_word (_ITOA_WORD_TYPE value, char *buf,
Packit 6c4009
			  unsigned int base,
Packit 6c4009
			  int upper_case) attribute_hidden;
Packit 6c4009
extern char *_fitoa (unsigned long long value, char *buf, unsigned int base,
Packit 6c4009
		     int upper_case) attribute_hidden;
Packit 6c4009
Packit 6c4009
#if !_ITOA_NEEDED
Packit 6c4009
/* No need for special long long versions.  */
Packit 6c4009
# define _itoa(value, buf, base, upper_case) \
Packit 6c4009
  _itoa_word (value, buf, base, upper_case)
Packit 6c4009
# define _fitoa(value, buf, base, upper_case) \
Packit 6c4009
  _fitoa_word (value, buf, base, upper_case)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#endif	/* itoa.h */