Task: My cat
Navigate to labs/lab-09/tasks/my-cat/support/src and checkout my_cat.c. We propose to implement the Linux command cat that reads one or more files, concatenates them (hence the name cat), and prints them to standard output.
- Inside the
tests/directory, you will need to runchecker.sh. The output for a successful implementation should look like this:
./checker.sh
make: Nothing to be done for 'all'.
Test 1: Comparing single file output..........................PASSED (+30 points)
Test 2: Comparing multiple files output.......................PASSED (+30 points)
Test 3: Testing empty file....................................PASSED (+30 points)
----------------------------------------
Final Score: 100/100 points
Good job!
----------------------------------------
-
Implement
rread()wrapper overread().read()system call does not guarantee that it will read the requested number of bytes in a single call. This happens when the file does not have enough bytes, or whenread()is interrupted by a signal.rread()will handle these situations, ensuring that it reads eithernum_bytesor all available bytes. -
Implement
wwrite()as a wrapper forwrite().The
write()system call may not write the requested number of bytes in a single call. This happens ifwrite()is interrupted by a signal.wwrite()will guarantee that it wrote the fullnum_bytes, retrying as necessary until all data is successfully written or an error occurs. -
Implement
cat().Use
rread()to read an entire file andwwrite()to write the contents to standard output. Keep in mind that the buffer size may not fit the entire file at once.
If you’re having difficulties solving this exercise, go through this reading material.