Improve to_block4().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@736 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-05-05 09:00:29 +00:00
parent fc50facaa3
commit cc2df5487a

View File

@@ -165,27 +165,38 @@ error:
return NULL; return NULL;
} }
#define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\ #define BLOCK(letter, n) do {ptr = strchr(alphabet, source[n]); \
if(!ptr) return -1;\ if(!ptr) return -1; \
i=ptr-alphabet;\ i = ptr - alphabet; \
SET_##letter(*block,i);\ SET_##letter(*block, i); \
} while(0) } while(0)
/* returns 0 if ok, -1 if not (ie invalid char into the stuff) */
static int to_block4(unsigned long *block, char *source,int num){ /* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */
char *ptr; static int to_block4(unsigned long *block, const char *source, int num) {
unsigned int i; char *ptr;
*block=0; unsigned int i;
if(num<1)
return 0; *block = 0;
BLOCK(A,0); /* 6 bits */ if (num < 1) {
BLOCK(B,1); /* 12 */
if(num<2)
return 0;
BLOCK(C,2); /* 18 */
if(num < 3)
return 0;
BLOCK(D,3); /* 24 */
return 0; return 0;
}
BLOCK(A, 0); /* 6 bit */
BLOCK(B,1); /* 12 bit */
if (num < 2) {
return 0;
}
BLOCK(C, 2); /* 18 bit */
if (num < 3) {
return 0;
}
BLOCK(D, 3); /* 24 bit */
return 0;
} }
/* num = numbers of final bytes to be decoded */ /* num = numbers of final bytes to be decoded */