Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
620 B

  1. #include "fmt.h"
  2. #include "textcode.h"
  3. #include "haveinline.h"
  4. unsigned int fmt_base64(char* dest,const char* src,unsigned int len) {
  5. register const unsigned char* s=(const unsigned char*) src;
  6. unsigned short bits=0,temp=0;
  7. unsigned long written=0,i;
  8. for (i=0; i<len; ++i) {
  9. temp<<=8; temp+=s[i]; bits+=8;
  10. while (bits>6) {
  11. if (dest) dest[written]=base64[((temp>>(bits-6))&63)];
  12. ++written; bits-=6;
  13. }
  14. }
  15. if (bits) {
  16. temp<<=(6-bits);
  17. if (dest) dest[written]=base64[temp&63];
  18. ++written;
  19. }
  20. while (written&3) { if (dest) dest[written]='='; ++written; }
  21. return written;
  22. }