Software /
code /
prosody
Comparison
util-src/encodings.c @ 441:4089b62b510c
Minor changes to C files (to prevent compiler warnings)
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 27 Nov 2008 21:47:13 +0500 |
parent | 432:fb19a5c14d44 |
child | 473:22b0e654c4cf |
comparison
equal
deleted
inserted
replaced
438:193f9dd64f17 | 441:4089b62b510c |
---|---|
1 /* | 1 /* |
2 * encodings.c | 2 * encodings.c |
3 * Lua library for base64, stringprep and idna encodings | 3 * Lua library for base64, stringprep and idna encodings |
4 */ | 4 */ |
5 | 5 |
6 // Newer MSVC compilers deprecate strcpy as unsafe, but we use it in a safe way | |
7 #define _CRT_SECURE_NO_DEPRECATE | |
8 | |
6 #include <string.h> | 9 #include <string.h> |
10 #include <malloc.h> | |
7 | 11 |
8 #include "lua.h" | 12 #include "lua.h" |
9 #include "lauxlib.h" | 13 #include "lauxlib.h" |
10 | 14 |
11 /***************** BASE64 *****************/ | 15 /***************** BASE64 *****************/ |
49 { | 53 { |
50 unsigned long tuple=c4+64L*(c3+64L*(c2+64L*c1)); | 54 unsigned long tuple=c4+64L*(c3+64L*(c2+64L*c1)); |
51 char s[3]; | 55 char s[3]; |
52 switch (--n) | 56 switch (--n) |
53 { | 57 { |
54 case 3: s[2]=tuple; | 58 case 3: s[2]=(char) tuple; |
55 case 2: s[1]=tuple >> 8; | 59 case 2: s[1]=(char) (tuple >> 8); |
56 case 1: s[0]=tuple >> 16; | 60 case 1: s[0]=(char) (tuple >> 16); |
57 } | 61 } |
58 luaL_addlstring(b,s,n); | 62 luaL_addlstring(b,s,n); |
59 } | 63 } |
60 | 64 |
61 static int Lbase64_decode(lua_State *L) /** decode(s) */ | 65 static int Lbase64_decode(lua_State *L) /** decode(s) */ |
72 switch (c) | 76 switch (c) |
73 { | 77 { |
74 const char *p; | 78 const char *p; |
75 default: | 79 default: |
76 p=strchr(code,c); if (p==NULL) return 0; | 80 p=strchr(code,c); if (p==NULL) return 0; |
77 t[n++]= p-code; | 81 t[n++]= (char) (p-code); |
78 if (n==4) | 82 if (n==4) |
79 { | 83 { |
80 base64_decode(&b,t[0],t[1],t[2],t[3],4); | 84 base64_decode(&b,t[0],t[1],t[2],t[3],4); |
81 n=0; | 85 n=0; |
82 } | 86 } |