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.
 
 
 
 

35 lines
753 B

  1. #include "textcode.h"
  2. #include "haveinline.h"
  3. static inline int dec(unsigned char x) {
  4. if (x>='A' && x<='Z') return x-'A';
  5. if (x>='a' && x<='z') return x-'a'+26;
  6. if (x>='0' && x<='9') return x-'0'+26+26;
  7. switch (x) {
  8. case '+': return 62;
  9. case '/': return 63;
  10. default: return -1;
  11. }
  12. }
  13. unsigned int scan_base64(const char *src,char *dest,unsigned int *destlen) {
  14. unsigned short tmp=0,bits=0;
  15. register const unsigned char* s=(const unsigned char*) src;
  16. const char* orig=dest;
  17. for (;;) {
  18. int a=dec(*s);
  19. if (a<0) {
  20. while (*s=='=') ++s;
  21. break;
  22. }
  23. tmp=(tmp<<6)|a; bits+=6;
  24. ++s;
  25. if (bits>=8) {
  26. *dest=(tmp>>(bits-=8));
  27. ++dest;
  28. }
  29. }
  30. *destlen=dest-orig;
  31. return (const char*)s-src;
  32. }