l64a.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <stdlib.h>
  17. /* Conversion table. */
  18. static const char conv_table[64] =
  19. {
  20. '.', '/', '0', '1', '2', '3', '4', '5',
  21. '6', '7', '8', '9', 'A', 'B', 'C', 'D',
  22. 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
  23. 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  24. 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
  25. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  26. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  27. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  28. };
  29. char * l64a (long int n)
  30. {
  31. unsigned long int m = (unsigned long int) n;
  32. static char result[7];
  33. char *p;
  34. /* The standard says that only 32 bits are used. */
  35. if (sizeof(m) != 4)
  36. m &= 0xffffffff;
  37. /* The value for N == 0 is defined to be the empty string,
  38. * this code provides that as well. */
  39. p = result;
  40. while (m)
  41. {
  42. *p++ = conv_table[m & 0x3f];
  43. m >>= 6;
  44. }
  45. *p = '\0';
  46. return result;
  47. }