COSC 350 System Software Lab#4




5/5 - (2 votes)

COSC 350 System Software Lab#4

How to submit
• For each program, you need write detailed comments for each statement.
• You need demonstrate each task in front of instructor during the next lab hours.
Task #1. In Task#8 in Lab3, you wrote a program to encode a file with character to a file with
ASCII code number. Write decoding program which covert output of Task#8 in Lab3 to original
input file.
Task #2: Write a C main function that takes one command-line argument, the name of an input
file. The input file contains exactly one integer spread out over a single line of up to 80
characters. For example, the integer 3579 is embedded in the line az3mqrm5t?7!z*&gqmzt9v.
Your program uses system calls to do the following:
a. open and read the input file, accumulating the discovered digit characters into a
character array (string).
b. Convert the string to an integer./taskdr (do not use atoi function).
c. Add 10 to the integer
d. convert the sum back to a string (using function convIntToStr)
e. make a system call to write the string to standard output.
Convert integer to string
Params: x is the int to be converted,
str is the string into which to write
Returns: length of the string
int convIntToStr(char * str, int x)
sprintf(str, “%d”, x);
return (strlen(str));
/* Returns a non-zero value if character c is a digit, zero otherwise. */
int isdigit(int c)
You need include five headers <unistd.h>, <fcntl.h>, <ctype.h>, <stdio.h> and <string.h> for
read write open system calls and sprint return strlen library functions.
Task #3. A palindrome is a word, phrase, number or other sequence of units that can be read
the same way in either direction. Write a C-function int palind(int fd1, int fd2) that takes two
independent file descriptors fd1 and fd2 that are already opened to the same file. The function
palind() uses lseek to scan the file and returns 1 if the file contains a palindrome (reads the
same forward and reverse) and 0 if not. You may assume that the file is well-formed and
contains just lower-case alphabetic characters on a single line. You also need write a main
function to test your palind() function works properly. The main function accept a file name as a
argument. The main() function open the file once and create duplicate file descriptor. And call
the function palind() to check whether the file contains palindrome or not.
Task #4.1. Write a simple program called hello.c and compile it and create executable file
named hello.
Write a C program for sequence of following task.
• By using system call, build following directory structure
• By using system calls, copy hello file under ~/Dir2/Dir21/
• By using system calls, make a symbolic link named toDir21 to directory Dir21
• By using system calls, make a symbolic link named toHello to executable file
Task#4.2. (Test for Task #4.1) Execute hello by using symbolic link toHello. Try to delete a file,
make directory by using symbolic link toDir21.
Task 5. Write your own mv named MyMv
By using bash command mv, you can move a file from current directory to another directory.
Write your own mv called MyMv by using system calls link() and unlink(). Your program named
MyMv can move a file from a current directory to a directory. Your program receives two
arguments: file name and path to a directory where the file need to move, or file name and
path to directory with a file name.
If the second argument is a directory, move a file to the directory. If the second argument is not
a directory, move file to directory as a file name.
• Move a file foo to under directory ~/separk/cosc350
o ./MyMv foo ~/separk/cosc350
• Move a file foo to under directory ~/separk/cosc350 named abc if there is no directory
named abc
o ./MyMv foo ~/separk/cosc350/abc
• Move a file foo to under directory ~/separk/cosc350 named foo if there is no directory
named foo
o ./MyMv foo ~/separk/cosc350/foo