ECE 357 Program 1 – Kitty solution

$24.99

Category:

Description

5/5 - (4 votes)

The objective of this assignment was to write a simple C program which is invoked from the command line in a UNIX environment, to utilize the UNIX system calls
for file I/O, and to properly handle and report error conditions. The program is described below as a “man page”, similar to that which describes standard UNIX
system commands.

“`
kitty – concatenate and copy files

USAGE:
kitty [-o outfile] infile1 […infile2….]
kitty [-o outfile]

DESCRIPTION:
This program opens each of the named input files in order, and concatenates the entire contents of each file,
in order, to the output. If an outfile is specified, kitty opens that file (once) for writing, creating it if
it did not already exist, and overwriting the contents if it did. If no outfile is specified, the output is
written to standard output, which is assumed to already be open.

During the concatenation, kitty will use a read/write buffer size of 4096 bytes.

Any of the infiles can be the special name – (a single hyphen). kitty will then concatenate standard input to the
output, reading until end-of-file, but will not attempt to re-open or to close standard input. The hyphen can be
specified multiple times in the argument list, each of which will cause standard input to be read again at that point.

If no infiles are specified, kitty reads from standard input until eof.

At the end of concatenating any file (including standard input), kitty will print a message to standard error giving
the number of bytes transferred (for that file), and the number of read and write system calls made. If the file was
observed to be a “binary” file, an additional warning message will be printed. The name of the file will also appear
in this message. In the case of standard input, the name will appear as <standard input>.

EXIT STATUS:
program returns 0 if no errors (opening, reading, writing or closing) were encountered.
Otherwise, it terminates immediately upon the error, giving a proper error report, and returns -1.
“`