#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "eps.h"
int main(int argc, char *argv[])
{
size_t size = 0;
int ret = 0, fd = 0;
char buf[500] = { 0 };
line_t *l = NULL;
line_t *ol = NULL;
if (argc < 2)
return 1;
fd = open(argv[1], O_RDONLY);
if (fd == -1)
return 1;
l = line_alloc();
if (l == NULL) {
close(fd);
return 1;
}
ol = line_alloc();
if (ol == NULL) {
close(fd);
return 1;
}
line_init(l, NULL, 5000);
line_init(ol, NULL, 5000);
while(1) {
memset((char *)buf, 0, 500);
ret = read(fd, buf, 500);
if (ret < 1)
break;
line_inject(l, buf, ret);
}
ret = base64_encode(ol, l);
if (!ret)
printf("Error encoding\n");
line_kill(l);
close(fd);
size = write(1, ol->data, ol->bytes);
if (size < ol->bytes) {
printf("Error writing\n");
return 0;
}
line_kill(ol);
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1