Sunteți pe pagina 1din 2

Assumptions:

1. For both questions input will be given through command line.


2. For both questions input will be path of the file to be reversed.
3. Directory "Assignment" will be created in the execution directory.
4. New file will be created in "Assignment" with name same as the input
file.

Q1.c:

Process:
0. The program analyzes the input filepath and stores the path of the new
file(to be created) in "path" variable.
(getpath() function)
1. The program takes the filepath as input from command line.
2. A directory named "Assignment" is created in present directory with
read, write, and execute permissions for only the current user.
(Using mkdir())
3. The input file is opened in read only mode.
(Using open())
4. A new file is created with the same name as input file in the Assignment
folder previously created.
The file has only read and write permissions for the current user and
is opened in write only mode.
If the file already exists, it is truncted.
(Using open())
5. The information about the input file is stored in "rev" variable;
(Using fstat())
6. If the size of the file is greater than "SIZE"(here: 1MB), then the
variable "size" is set to SIZE, else it is set to the size of the file.
This variable defines the chunk of data to be read and written at once.
7. A loop starts reading the file from (end-size) bytes reading size bytes
at a time, reversing the buffer and writing to the new file.
(Using read() and write())

Errors handled:
1. Input file not found.
2. New file not created.
3. No command line arguments given.
4. More than one command line arguments given.

Q2.c:

Process:
0. The program analyzes the input filepath and stores the path of the new
file(to be created) in "path" variable.
(getpath() function)
1. The program takes the filepath as input from command line.
2. The directory named "Assignment" is opened.
(Using opendir())
3. The information about the directory is saved in the variable "stats".
(Using stat())
4. The permissions of the directory are printed.
(printperm() function)
5. The input file and the new_ created file is opened in read only mode.
(Using open())
6. The input file and new file contents are compared to verify the reversal
process.
(isreverse() funciton)
7. The information about the input file is saved in the variable "stats".
(Using stat())
8. The permissions of the input file are printed.
(printperm() function)
9. The information about the new file is saved in the variable "stats".
(Using stat())
10. The permissions of the new file are printed.
(printperm() function)

Errors handled:
1. Input file not found.
2. New file not created.
3. No command line arguments given.
4. More than one command line arguments given.
5. "Assignment" directory not created.

S-ar putea să vă placă și