(root)/
glibc-2.38/
stdlib/
l64a.c
       1  /* Copyright (C) 1995-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library; if not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #include <stdlib.h>
      19  
      20  /* Conversion table.  */
      21  static const char conv_table[64] =
      22  {
      23    '.', '/', '0', '1', '2', '3', '4', '5',
      24    '6', '7', '8', '9', 'A', 'B', 'C', 'D',
      25    'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
      26    'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
      27    'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
      28    'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
      29    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
      30    's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
      31  };
      32  
      33  char *
      34  l64a (long int n)
      35  {
      36    unsigned long int m = (unsigned long int) n;
      37    static char result[7];
      38    int cnt;
      39  
      40    /* The standard says that only 32 bits are used.  */
      41    m &= 0xffffffff;
      42  
      43    if (m == 0ul)
      44      /* The value for N == 0 is defined to be the empty string. */
      45      return (char *) "";
      46  
      47    for (cnt = 0; m > 0ul; ++cnt)
      48      {
      49        result[cnt] = conv_table[m & 0x3f];
      50        m >>= 6;
      51      }
      52    result[cnt] = '\0';
      53  
      54    return result;
      55  }