diff options
Diffstat (limited to 'base64.c')
-rw-r--r-- | base64.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/base64.c b/base64.c index da7e99e..87843d6 100644 --- a/base64.c +++ b/base64.c @@ -30,10 +30,14 @@ static void usage(const char *name) { fprintf(stderr, "usage: %s [-d] [FILE]\n", name); } +char *base64(char *input, unsigned dflg){ + return input; +} + int main(int argc, char **argv) { int c; - unsigned dflg; + unsigned dflg = 0; const char *name = argv[0]; while ((c = getopt(argc, argv, "dh")) != -1) { switch(c) { @@ -51,29 +55,33 @@ int main(int argc, char **argv) { } } int fd; - for (; optind < argc; optind++) { - if (*argv[optind] == '-') { - fd = STDIN_FILENO; - } else { - if ((fd = open(argv[optind], O_RDONLY)) == -1 ) { - perror(argv[optind]); + if (optind == argc) { + base64(STDIN_FILENO, dflg); + } else { + for (; optind < argc; optind++) { + if (*argv[optind] == '-') { + fd = STDIN_FILENO; + } else { + if ((fd = open(argv[optind], O_RDONLY)) == -1 ) { + perror(argv[optind]); + return 1; + } + } + char buf[BUF_SIZE] = {'\0'}; + if (read(fd, buf, BUF_SIZE) == -1 ) { + perror("read"); return 1; } - } - char buf[BUF_SIZE] = {'\0'}; - if (read(fd, buf, BUF_SIZE) == -1 ) { - perror("read"); - return 1; - } - printf("%s\n", buf); + printf("%s\n", buf); - if (close(fd) != 0) { - perror("close"); - return 1; + if (close(fd) != 0) { + perror("close"); + return 1; + } } + } - } return 0; } |