QuestionQuestion

1. Create a file called openClose.in. You may cut and paste content from the lab notes into this file.

2. Write a C++ program 'openClose.cpp' that copies openClose.in to a file called openClose.out. Use open(), read(), write() and close() system calls. Use a buffer size of 32 bytes for reads and writes.
A call to your program will look something like this:
openClose openClose.in openClose.out
If you have the wrong number of arguments, your code will produce a message like the following:
%openClose
Usage: openClose <inFile> <outFile>
Check for errors and use perror. For instance, you should see something like the following if the user types an nonexistent input file:
%openClose noSuchFile openClose.out

inFile is noSuchFile fd = -1         errno = 2
InFile Error: No such file or directory
      
3. Call fstat() in the openClose.cpp program and print the following information about openClose.out: the file size (in bytes), the owner and group IDs, and the time it was last modified. The output can be in the following format:
This is the status of openClose.out
File Size      Owner       Group ID    Last Modified
815             10064          200             1097124530
If you want to do more, you can output in the following format:
This is the status of openClose.out
File Size      Owner       Group ID    Last Modified
815               nova          csfac          Wed Oct 6 22:48:50 2004
To do this, you can make use of library calls: getgrgid, getpwuid, and ctime. Check out the man pages for these calls.
You do not have to use the write system call for this last step. If you want, you can use printf to format your output nicely.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#!/bin/bash

echo Goal: show that openClose.out does not exist
ls -l
echo Goal: display the contents of the input file
cat openClose.in
echo Result: error message-not enough arguments
./openClose
echo Result: error message-not enough arguments
./openClose openClose.in
echo Result: error message-no such file
./openClose noSuchFile openClose.out
echo Result: no errors runs to completion and creates openClose.out
./openClose openClose.in openClose.out
echo Goal: show that openClose.out has been created
ls -l
echo Goal: display the contents of the output file
cat openClose.out
echo Result: error message-permission denied on creating openClose.out
./openClose openClose.in /openClose.out...
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Linux Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats