localedata/unicode-gen/utf8_gen.py: adapt regexp to get relevant lines from EastAsian...
[glibc.git] / stdlib / l64a.c
blob5fd93cf7aeab957e6e138ff418f1b7c92f663089
1 /* Copyright (C) 1995-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #include <stdlib.h>
20 /* Conversion table. */
21 static const char conv_table[64] =
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'
33 char *
34 l64a (long int n)
36 unsigned long int m = (unsigned long int) n;
37 static char result[7];
38 int cnt;
40 /* The standard says that only 32 bits are used. */
41 m &= 0xffffffff;
43 if (m == 0ul)
44 /* The value for N == 0 is defined to be the empty string. */
45 return (char *) "";
47 for (cnt = 0; m > 0ul; ++cnt)
49 result[cnt] = conv_table[m & 0x3f];
50 m >>= 6;
52 result[cnt] = '\0';
54 return result;