aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-05-05 09:00:29 +0000
committerAndreas Schneider <mail@cynapses.org>2009-05-05 09:00:29 +0000
commitcc2df5487a4457078a27d001cc67d911c0511be5 (patch)
treea837160712408ace0f8e3db879a5d54cce450e13 /libssh
parentfc50facaa39ed27f8f4180aad2a1adb414541ad4 (diff)
downloadlibssh-cc2df5487a4457078a27d001cc67d911c0511be5.tar.gz
libssh-cc2df5487a4457078a27d001cc67d911c0511be5.tar.xz
libssh-cc2df5487a4457078a27d001cc67d911c0511be5.zip
Improve to_block4().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@736 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/base64.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/libssh/base64.c b/libssh/base64.c
index 95f8b59b..7cb2046b 100644
--- a/libssh/base64.c
+++ b/libssh/base64.c
@@ -165,27 +165,38 @@ error:
return NULL;
}
-#define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\
- if(!ptr) return -1;\
- i=ptr-alphabet;\
- SET_##letter(*block,i);\
- } 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){
- char *ptr;
- unsigned int i;
- *block=0;
- if(num<1)
- return 0;
- BLOCK(A,0); /* 6 bits */
- BLOCK(B,1); /* 12 */
- if(num<2)
- return 0;
- BLOCK(C,2); /* 18 */
- if(num < 3)
- return 0;
- BLOCK(D,3); /* 24 */
+#define BLOCK(letter, n) do {ptr = strchr(alphabet, source[n]); \
+ if(!ptr) return -1; \
+ i = ptr - alphabet; \
+ SET_##letter(*block, i); \
+ } while(0)
+
+/* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */
+static int to_block4(unsigned long *block, const char *source, int num) {
+ char *ptr;
+ unsigned int i;
+
+ *block = 0;
+ if (num < 1) {
+ 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 */