CENG251 - Assignment #3: The Little Functions
CENG251 - Assignment #3: The Little Functions
When the problem tells you process multiple files or directories these should be provided as a list on the
command line, not read in.
When you are asked to test the success or failure of a function, set errno to zero immediately after your
test as it does not always automatically reset on its own.
You are encouraged to use the strace and ltrace commands to view the function calls used to implement
the bash shell commands, how do not use the at version of the commands. Do NOT give your
commands the same name as the shell command as when you go to test the program you’ll be running
the original command, not your code.
1. Use the link , symlink and access functions to implement your own version of the link
command: (4 marks)
a. Write a getopt loop to capture the flags -s and -f which can appear at any position in
the command line. (1)
b. If -f is present, delete the target file immediately after the getopt loop. (.5)
c. After the loop, if -s is present in the command line, use symlink to create a symbolic
link. If -s is not present then use the link function. (1)
d. After attempting to create the link use all 3 of errno, perror and the return value from
the link function to verify that your link function works.
e. Use the system function to verify success or failure of the command. (1.5)
2. Use the C chmod function to implement the equivalent of the octal version of the bash shell’s
chmod command. (4 marks, 2 for code, 2 for testing)
3. Before writing this program note the group id # of your alternate group (sharks, minnows,
dolphins) using the id command. Implement the following command: (3 marks)
And that these values can be passed to any command, as demonstrated in class:
showArgs `seq 2 3 70 | shuf -n 10`
Write a program that is passed a list of record numbers in random order on the command
line and uses a combination of fseek, fread and frwrite to copy these records from infile to
outfile. Open outfile in append mode that that you are always adding record. (3 marks)