CmpE106
Spring 2018 Programming Assignment 6
Due Date: 18 Apr.
Goal: File properties program
Instructions:
Step 1. Creating the assembly language file
Everything should be done the same way as the previous assignment.
Step 2. The application area
This assignment will give practice at using a struct and working with C library functions.
The goal is very simple. Your program should take a file name and print the time since the file was last modified.
We have already discussed in class how to find out the current time.
The tool you need to determine when a file was last modified is stat() or fstat(). These will return a lot of information about a file. You can ignore almost all of this information except for the time modified.
See http://manpages.ubuntu.com/manpages/wily/man2/lstat.2.html Additional discussion: https://stackoverflow.com/questions/11765683/how-to-
read-file-folder-properties-in-linux
Note that stat can be used from the command line as well (see http://labtestproject.com/linuxcmd/stat.html) but we want to call it as a function.
Time.h: http://pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html Discussion of the difference between timeval and timespec:
https://stackoverflow.com/questions/31275131/c-timeval-vs-timespec
https://stackoverflow.com/questions/11153334/timespec-not-found-in-time-h
Aside: ISO 8601 date format: https://askubuntu.com/questions/355188/date- format-in-unix
Pg. 1
CmpE102 Spring 2018 Programming Assignment 6
Step 3. What your code should do
- Your code should use STDIN and STDOUT for input and output. (This is the default.) Use redirection on the command line to read from a file and write to a file. Or you can take the file name from the command line as I did with the Cryptoquip helper example I went over in class.
- Your code should take a file name as input.
- The code should output the length of time since the file was last modified. Theformat is days, hours, minutes and seconds.
- The program should call stat() or similar function to get the modificationtime of the file in question.
- This program should use glibc functions for input and output..
Hints
- There may be minor differences in details from one system to another. Be prepared to do a little experimentation. (See the discussion of padding in structs that we covered in class for an example of how to do experiments of this type.)
- I don’t know how to do this on a Mac, but it should be something fairly similar to Linux. Search online for information.
- I suggest that you try it in C first to get a handle on how to approach the problem before you go to assembly language.
- There is lots of information on Linux topics available online. The links I have provided above are just a sample.
Step 4. Turning in the assignment
Turn in the following:
- Commented listing file.
- Demonstration of functioning for several different files that were modifiedseveral days previously.
- Include command line output of ls -l for the files so we can verify theresults.
Pg. 2
CmpE102 Spring 2018 Programming Assignment 6