diff options
-rw-r--r-- | base64.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/base64.c b/base64.c index 1a73eb6..d63c301 100644 --- a/base64.c +++ b/base64.c @@ -121,9 +121,15 @@ int main(int argc, char **argv) { } ssize_t bytes; char buf[BUF_SIZE] = {'\0'}; - if ((bytes = read(fd, buf, BUF_SIZE)) <= 0 ) { - perror("read"); - return 1; + while (1){ + if ((bytes = read(fd, buf, BUF_SIZE)) <= 0 ) { + if (bytes == 0) break; /* read returns 0 when EOF has been reached */ + perror("read"); + return 1; + } + + char *output = base64(buf, bytes, dflg); + printf("%s\n", output); } if (close(fd) != 0) { @@ -131,9 +137,6 @@ int main(int argc, char **argv) { return 1; } - char *output = base64(buf, bytes, dflg); - printf("%s\n", output); - return 0; } |