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.
 
 
 
 

43 lines
1.0 KiB

  1. #include "textcode.h"
  2. size_t scan_uuencoded(const char *src,char *dest,size_t *destlen) {
  3. size_t len;
  4. size_t tmp;
  5. register const unsigned char* s=(const unsigned char*) src;
  6. size_t i=0;
  7. if ((len=*s-' ')>64) return 0;
  8. len&=63;
  9. ++s;
  10. while (len>0) {
  11. if (s[0]-' '>64 || s[1]-' '>64 || s[2]-' '>64 || s[3]-' '>64) return 0;
  12. tmp=(((s[0]-' ')&077) << (3*6)) +
  13. (((s[1]-' ')&077) << (2*6)) +
  14. (((s[2]-' ')&077) << (1*6)) +
  15. (((s[3]-' ')&077));
  16. s+=4;
  17. if (len) { if (dest) dest[i++]=tmp>>16; --len; }
  18. if (len) { if (dest) dest[i++]=tmp>>8; --len; }
  19. if (len) { if (dest) dest[i++]=tmp&0xff; --len; }
  20. }
  21. if (destlen) *destlen=i;
  22. return (const char*)s-src;
  23. }
  24. #ifdef UNITTEST
  25. #include <assert.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. int main() {
  29. char buf[100];
  30. size_t i;
  31. memset(buf,0,100);
  32. assert(scan_uuencoded("&9FYO<F0*",buf,&i)==9 && i==6 && !memcmp(buf,"fnord\n",7));
  33. memset(buf,0,100);
  34. assert(scan_uuencoded("%9FYO<F0`",buf,&i)==9 && i==5 && !memcmp(buf,"fnord",6));
  35. return 0;
  36. }
  37. #endif