version 1.1.2.1, 2012/09/17 13:05:47
|
version 1.4, 2016/09/14 15:12:22
|
Line 1
|
Line 1
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <fcntl.h> |
#include <fcntl.h> |
|
#include <elwix.h> |
#include <aitwww.h> |
#include <aitwww.h> |
|
|
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
int fd = STDOUT_FILENO; | int rlen, fd = STDIN_FILENO; |
| ait_val_t *e, *d, s, src; |
|
|
if (argc > 1) { |
if (argc > 1) { |
fd = open(argv[1], O_RDONLY); |
fd = open(argv[1], O_RDONLY); |
Line 15 main(int argc, char **argv)
|
Line 18 main(int argc, char **argv)
|
perror("open"); |
perror("open"); |
return 1; |
return 1; |
} |
} |
|
AIT_SET_STRSIZ(&src, lseek(fd, 0, SEEK_END)); |
|
lseek(fd, 0, SEEK_SET); |
|
} else |
|
AIT_SET_STRSIZ(&src, USHRT_MAX + 1); |
|
rlen = read(fd, AIT_GET_STR(&src), AIT_LEN(&src)); |
|
if (rlen == -1) { |
|
perror("read"); |
|
if (fd > 2) |
|
close(fd); |
|
return 2; |
|
} else { |
|
AIT_INIT_VAL2(&s, string); |
|
AIT_SET_STRLCPY(&s, AIT_GET_STR(&src), rlen); |
|
AIT_FREE_VAL(&src); |
} |
} |
|
|
if (fd > 2) |
if (fd > 2) |
close(fd); |
close(fd); |
|
|
|
e = www_b64encode(&s); |
|
if (!e) { |
|
ELIBERR(www); |
|
return 3; |
|
} |
|
printf("\n\n--- encode base64 len=%u ---\n%s\n", AIT_LEN(e), AIT_GET_STR(e)); |
|
|
|
d = www_b64decode(e); |
|
if (!d) { |
|
ELIBERR(www); |
|
ait_freeVar(&e); |
|
return 4; |
|
} |
|
printf("\n\n--- decode base64 len=%u ---\n%s\n", AIT_LEN(d), AIT_GET_STR(d)); |
|
|
|
if ((rlen = ait_cmpVar(&s, d)) < 0) |
|
printf("\n\n>>> FAIL = -1\n"); |
|
else if (!rlen) |
|
printf("\n\n>>> PASS = 0\n"); |
|
else |
|
printf("\n\n>>> FAIL = 1\n"); |
|
|
|
ait_freeVar(&d); |
|
ait_freeVar(&e); |
|
AIT_FREE_VAL(&s); |
return 0; |
return 0; |
} |
} |