Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Clarke 2022 A UNIXs cat command concatenates a number of said files by reading their contents and then writing them in a direct sequence. Create

Clarke 2022

A UNIXs cat command concatenates a number of said files by reading their contents and then

writing them in a direct sequence.

Create a C program named graycats.c.

for this code, you will re-implement a simple form of cat which takes file or more than one files

paths as command-line arguments (up to the limit prescribed by Linux) and writes the

contents of the files to stdout.

You may use open, read, write, and close POSIX API calls as well as their related

constant definitions.

You can find documentation about each of these API calls in section two of the Linux

man pages (e.g., man 2 open).

You may NOT use any functions defined in stdio.h or stdio

Man pages: Recall that the UNIX manual (man) pages are a very good resource to learn. Each man

page enumerates the headers required to use a POSIX API call or function and describes the

functions interface and semantics. You will find POSIX API calls in section two of the man pages (for

example, man 2 open).

open: Opening your input file does not really require any special flags, so you can pass 0 as the flag

argument to open.

Buffers: The read and write POSIX API calls operate on buffers of bytes. The easiest way to

allocate such a buffer is by declaring a stack char array. This is described in K&R [1, 5.3].

Error handling: Each of the POSIX API calls you are to use return a -1 if they encounter any type of error.

Your program should write a small message to stderr (i.e., file descriptor 2/STDERR_FILENO) if it

encounters an error. Doing this will aid in troubleshooting, and it will make your program more

robust.

image text in transcribed

As an example, the command ./graycat /etc/passwd /etc/group should produce something like: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbinologin daemon:x:2:2: daemon:/sbin:/sbinologin root:x:0: bin:x:1: daemon:x:2: The first three lines come from /etc/passwd, and the next three lines come from /etc/group. As an example, the command ./graycat /etc/passwd /etc/group should produce something like: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbinologin daemon:x:2:2: daemon:/sbin:/sbinologin root:x:0: bin:x:1: daemon:x:2: The first three lines come from /etc/passwd, and the next three lines come from /etc/group

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions