b64dump.c.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. b64dump.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='Attributes.c.html' title=' Attributes.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='basespec.c.html' title=' basespec.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * size_t b64dump (void const * memory, size_t extent, size_t column, FILE *fp);
  24. *
  25. * base64.h
  26. *
  27. * base64 encode a memory region and write to a text file; wrap
  28. * the output at a given column; do not wrap when column is 0;
  29. *
  30. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  31. * Copyright (c) 2001-2006 by Charles Maier Associates;
  32. * Licensed under the Internet Software Consortium License;
  33. *
  34. *--------------------------------------------------------------------*/
  35. #ifndef B64DUMP_SOURCE
  36. #define B64DUMP_SOURCE
  37. #include &lt;stdio.h&gt;
  38. #include &lt;stdint.h&gt;
  39. #include &quot;../tools/base64.h&quot;
  40. #include &quot;../tools/types.h&quot;
  41. void b64dump (void const * memory, size_t extent, size_t column, FILE *fp)
  42. {
  43. byte * offset = (byte *)(memory);
  44. unsigned encode = 0;
  45. while (extent)
  46. {
  47. uint32_t word = 0;
  48. unsigned byte = 0;
  49. unsigned bits = BASE64_WORDSIZE - BASE64_BYTESIZE;
  50. while ((bits) &amp;&amp; (extent))
  51. {
  52. bits -= BASE64_BYTESIZE;
  53. word |= *offset &lt;&lt; bits;
  54. offset++;
  55. extent--;
  56. byte++;
  57. }
  58. if (byte++)
  59. {
  60. bits = BASE64_WORDSIZE - BASE64_BYTESIZE;
  61. while ((bits) &amp;&amp; (byte))
  62. {
  63. bits -= BASE64_CHARSIZE;
  64. putc (BASE64_CHARSET [(word &gt;&gt; bits) &amp; BASE64_CHARMASK], fp);
  65. byte--;
  66. encode++;
  67. }
  68. while (bits)
  69. {
  70. bits -= BASE64_CHARSIZE;
  71. putc ('=', fp);
  72. encode++;
  73. }
  74. if ((column) &amp;&amp; !(encode%column))
  75. {
  76. putc ('\n', fp);
  77. }
  78. }
  79. }
  80. return;
  81. }
  82. #endif
  83. </pre>
  84. <div class='footerlink'>
  85. [<a href='Attributes.c.html' title=' Attributes.c '>PREV</a>]
  86. [<a href='toolkit.html' title=' Index '>HOME</a>]
  87. [<a href='basespec.c.html' title=' basespec.c '>NEXT</a>]
  88. </div>
  89. </body>
  90. </html>