Back to index

glibc  2.9
_itoa.h
Go to the documentation of this file.
00001 /* Internal function for converting integers to ASCII.
00002    Copyright (C) 1994-1999,2002,2003,2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _ITOA_H
00021 #define _ITOA_H
00022 
00023 #include <limits.h>
00024 
00025 /* Convert VALUE into ASCII in base BASE (2..36).
00026    Write backwards starting the character just before BUFLIM.
00027    Return the address of the first (left-to-right) character in the number.
00028    Use upper case letters iff UPPER_CASE is nonzero.  */
00029 
00030 extern char *_itoa (unsigned long long int value, char *buflim,
00031                   unsigned int base, int upper_case);
00032 
00033 extern const char _itoa_upper_digits[];
00034 extern const char _itoa_upper_digits_internal[] attribute_hidden;
00035 extern const char _itoa_lower_digits[];
00036 extern const char _itoa_lower_digits_internal[] attribute_hidden;
00037 
00038 #ifndef NOT_IN_libc
00039 extern char *_itoa_word (unsigned long value, char *buflim,
00040                       unsigned int base, int upper_case);
00041 #else
00042 static inline char * __attribute__ ((unused, always_inline))
00043 _itoa_word (unsigned long value, char *buflim,
00044            unsigned int base, int upper_case)
00045 {
00046   const char *digits = (upper_case
00047 # if defined IS_IN_rtld
00048                      ? INTUSE(_itoa_upper_digits)
00049                      : INTUSE(_itoa_lower_digits)
00050 # else
00051                      ? _itoa_upper_digits
00052                      : _itoa_lower_digits
00053 # endif
00054                      );
00055 
00056   switch (base)
00057     {
00058 # define SPECIAL(Base)                                                      \
00059     case Base:                                                              \
00060       do                                                             \
00061        *--buflim = digits[value % Base];                             \
00062       while ((value /= Base) != 0);                                         \
00063       break
00064 
00065       SPECIAL (10);
00066       SPECIAL (16);
00067       SPECIAL (8);
00068     default:
00069       do
00070        *--buflim = digits[value % base];
00071       while ((value /= base) != 0);
00072     }
00073   return buflim;
00074 }
00075 # undef SPECIAL
00076 #endif
00077 
00078 /* Similar to the _itoa functions, but output starts at buf and pointer
00079    after the last written character is returned.  */
00080 extern char *_fitoa_word (unsigned long value, char *buf, unsigned int base,
00081                        int upper_case) attribute_hidden;
00082 extern char *_fitoa (unsigned long long value, char *buf, unsigned int base,
00083                    int upper_case) attribute_hidden;
00084 
00085 #if LONG_MAX == LLONG_MAX
00086 /* No need for special long long versions.  */
00087 # define _itoa(value, buf, base, upper_case) \
00088   _itoa_word (value, buf, base, upper_case)
00089 # define _fitoa(value, buf, base, upper_case) \
00090   _fitoa_word (value, buf, base, upper_case)
00091 #endif
00092 
00093 #endif /* itoa.h */