l64a.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <stdlib.h>
  16. /* Conversion table. */
  17. static const char conv_table[64] =
  18. {
  19. '.', '/', '0', '1', '2', '3', '4', '5',
  20. '6', '7', '8', '9', 'A', 'B', 'C', 'D',
  21. 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  22. 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  23. 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
  24. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  25. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  26. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  27. };
  28. char * l64a (long int n)
  29. {
  30. unsigned long int m = (unsigned long int) n;
  31. static char result[7];
  32. char *p;
  33. /* The standard says that only 32 bits are used. */
  34. if (sizeof(m) != 4)
  35. m &= 0xffffffff;
  36. /* The value for N == 0 is defined to be the empty string,
  37. * this code provides that as well. */
  38. p = result;
  39. while (m)
  40. {
  41. *p++ = conv_table[m & 0x3f];
  42. m >>= 6;
  43. }
  44. *p = '\0';
  45. return result;
  46. }