Back
CS 456 Home

Assignment h2: Basic File I/O

Due Date: Feb 24 @ 8AM EST

In this assignment, you will be doing some work involving the four basic I/O 
functions, open, read, write, and close. You are going to take two programs 
that are already working and making a few specified improvements.

These programs are:
1. copyim.c - a simplified version of the cp command. You will make the 
   following improvements:
   	- This file is currently hardcoded to only read up to 1024 bytes. 
	  Change this so that it will read up to whatever the size of the file 
          is.
	- The permissions of the target file are currently hardcoded to 0666 
          (read-write for everyone), change this so that the target file has 
 	  the same permissons as the source file  

2. concat.c - a simplified version of the cat command. You will make the 
   following improvements.
	- As in copyim.c, this is currently hardcoded to only read up to 1024 
          bytes. Change that so it will read up to whatever the size of the 
          file is
	- This file can currently only accept one file on the command line. 
	  Make it so that if I provide more than 1 file, it will print that 
          file too.

	  So in the finished program:
	  >./concat hello
	  Would print the contents of the file "hello" to standard output

	  and the following
	  >./concat hello world blah 
	  Would print the contents of the files "hello", then the contents of 
	  "world" and the contents of the file "blah" in that order

I have included an additional file in this folder: extras.h. This is a header 
file that i've written that goes with these two programs. Inside it contains 
two functions get_fdSize which gets the size of a file, and get_fdPerms, which 
gets the permissions of a file. If you look inside the file, you'll see that 
it involves a variant of the stat function, which we'll cover in Chapter 6. 

You do NOT need to make any modifications to this extras.h file, but you will 
be using the two functions in this file to complete this assignment. Note that 
the needed include statement for extras.h is already in your source code files, 
all you have to do is call the function.

There already is some code in each of these source files. Use that existing 
code and the comments to help you finish the program. You can also look at the 
examples in the h2ex directory of the In-Class Code to help you. I ask that you 
not depend on Generative AI (like ChatGPT, etc) to do this assignment. You 
should be able to do this assignment based on the examples given in the book 
and in the In-class code.

To pick up this assignment, copy the h1 folder into your cs456 directory by running: 
		     cp -R /home/cs456/h2/ ~/cs456/
		OR:  hw_get.py cs456 h2

Then use a text editor (like vi, nano, emacs) to open it and make the necessary 
edits to accomplish these objectives.

Once finished, leave it in that directory. I will run a script to collect the 
files when the due date approaches.