This is an old revision of the document!
Corning Community College
CSCS2730 Systems Programming
~~TOC~~
To implement a programmatic solution of an existing system command. Our first task will be to implement our own version of the chmod(1) command.
The chmod(1) command allows one to change the permissions of a file (that they have permission to change permissions on).
As we've started exploring system calls, we see that in many cases there is a surprising similarity between the executable command and the system call name.
It turns out that is also the case here with chmod:
lab46:~$ apropos chmod chmod (1) - change file mode bits chmod (2) - change permissions of a file
We're interested in that section 2 manual page. We see the function prototype for chmod is:
int chmod(const char *pathname, mode_t mode);
It is your task to write the program that will use the above method to compute the square of the input value ending with a 5 (you are to input the entire number, including the 5 at the end).
Your program should:
lab46:~/src/cprog/sof0$ ./sof0 Enter value: 75 75 x 75 = 5625 lab46:~/src/cprog/sof0$
The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate.
Note how the two “75” values are left-justified within a 3-space slot (with the multiplication 'x' and equal sign '=' being padded with a space on either side). This information should all be displayed to STDERR.
Similarly, here's an example of 105×105:
lab46:~/src/cprog/sof0$ ./sof0 Enter value: 105 105 x 105 = 11025 lab46:~/src/cprog/sof0$
The 'x' and '=' padding persists, but because we're squaring a 3-digit value vs. a 2-digit value, we occupy the entire allocated space on the screen.
If you'd like to verify successful output to STDOUT/STDERR, you can perform the following tests. First, verify that the answer (and ONLY the answer), is being sent to STDOUT – we do this by eliminating STDERR entirely:
lab46:~/src/cprog/sof0$ ./sof0 2> /dev/null <<< 105 11025 lab46:~/src/cprog/sof0$
What we are doing here is two-fold:
Similarly, if we were to eliminate STDOUT entirely (for verifying STDERR output):
lab46:~/src/cprog/sof0$ ./sof0 1> /dev/null Enter value: 75 75 x 75 = lab46:~/src/cprog/sof0$
What we are doing here:
One of the tests I will perform for output compliance of your code will involve comparing your program's output against a range of input values, to see if they all output in conformance with project specifications.
I will make use of a checksum to verify exactness.
You will need to run this from your sof0 project directory with a compiled and operational binary by the name of sof0.
You can check your project by typing in the following at the prompt:
lab46:~/src/cprog/sof0$ pchk cprog sof0
If all aligns, you will see this:
================================================== = CPROG sof0 project output validation tool = ================================================== sof0 checksum is: 822a47fb2a45845500b6c10878045bd5 your checksum is: 822a47fb2a45845500b6c10878045bd5 ================================================== verification: SUCCESS! ==================================================
If something is off, your checksum will not match the sof0 checksum, and verification will instead say “MISMATCH”, like follows (note that a mismatched checksum can be anything, and likely not what is seen in this example):
================================================== = CPROG sof0 project output validation tool = ================================================== sof0 checksum is: 822a47fb2a45845500b6c10878045bd5 your checksum is: 92af264c86823a61529948caaeac53e0 ================================================== verification: MISMATCH ==================================================
These are things I'd like you to contemplate, even use as potential material on your weekly journal entry. The more you think about and understand the problem, the better your ability to solve it and other problems.
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ submit cprog sof0 sof0.c Submitting cprog project "sof0": -> sof0.c(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
I'll be looking for the following:
52:sof0:final tally of results (52/52) *:sof0:adequate indentation and comments in sof0.c [4/4] *:sof0:data stored and calculated in correct and separate variables [4/4] *:sof0:effective usage of fprintf() and fscanf() [4/4] *:sof0:program uses indicated algorithm [12/12] *:sof0:output conforms to project specifications [12/12] *:sof0:runtime tests of sof0.c succeed [12/12] *:sof0:no negative compiler messages for sof0.c [4/4]