Copying the linux tee command

Here's a C-program that I have written to imitate the linux tee command with the option -a through which the input is appended to the previous file.

#include <sys/stat.h>
#include "tlpi_hdr.h"
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
    int outputFd;
    int openFlags;
    mode_t filePerms;
    char c;
    int opt, append = 0;

    if(argc > 3 || (argc >= 2 && strcmp(argv[1], "--help") == 0))
        usageErr("%s [filename]\n", argv[0]);

    if(argc >= 2) {
        if(argc == 3) {
            while((opt = getopt(argc, argv, "a")) != -1) {
                if(opt == 'a')
                    append = 1;
            }
        }
        if(append == 1)
            openFlags = O_CREAT | O_WRONLY | O_APPEND;
        else
            openFlags = O_CREAT | O_WRONLY | O_TRUNC;

        filePerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
                    S_IROTH | S_IWOTH;      /* rw-rw-rw- */
        outputFd = open(argv[argc - 1], openFlags, filePerms);
        if(outputFd == -1)
            errExit("opening file %s", argv[1]);
    }

    while ((c = getchar()) != EOF) {
        printf("%c", c);
        if(argc >= 2) {
            if(write(outputFd, &c, 1) != 1)
                fatal("couldn't write whole buffer");
        }
    }

    if(close(outputFd) == -1)
        errExit("close output");

    exit(EXIT_SUCCESS);
}

Here's what the tee doc says

Copy standard input to each FILE, and also to standard output.

Here are some outputs from my program:

With no file:

$ ./liketee 
hello world
hello world
how is it going?
how is it going?

With a file as an input:

$ ./liketee hello.txt
hello world
hello world
how is it going?
how is it going?
^C
$ cat hello.txt 
hello world
how is it going?

Again running the same command truncates the file:

$ ./liketee hello.txt
this is some
this is some
new text
new text
^C
$ cat hello.txt 
this is some
new text

However, if we pass -a as an argument, then the same file is used and the new data is just appended.

$ ./liketee hello.txt -a
let's append
let's append
this to the file
this to the file
^C
$ cat hello.txt 
this is some
new text
let's append
this to the file