EE469 Lab 1: Spring 2000



Objective: Learn about system calls in Unix.

(1) What is a system call?
(2) Why are system calls  provided?
(3) (a) Compile the program called example.c (given below) to
	exercise the system calls opendir(), stat() and
	gettimeofday().

	opendir(dirname): opens a directory stream 
			  corresponding to the directory
			  named by the dirname argument
	stat(path, buf) : obtains information about the file
			  pointed to by path into structure
			  buf.
	gettimeofday(tp, tzp) :
			  obtains elapsed seconds and 
			  microseconds since 00:00 GMT, 
			  January 1, 1970.

    (b) Write a program using the above system calls to
	tells all files that were created in the past 24
	hours in the directory /home/shay/g/ee469/labs/01/testfiles/




Pre-lab Component Due at start of Lab class:

Turn in answers to questions 1 and 2 above and your design for 3(b).


Example

#include 
#include 
#include 
#include 
#include 

int main()
{
    int s;
    DIR *dir;
    struct dirent *entry;
    FILE *file;
    struct stat statptr;
    struct timeval tp;
    struct timezone tzp;
    time_t last_modified_time, current_time;


    /************************************/
    /* read the directory's contents,	*/
    /* print out the name of each entry.*/
    /************************************/
    dir = opendir(".");

    if (dir == NULL ) printf("dir: file not found\n");

    printf("Directory contents:\n");

    while ((entry = readdir(dir)) != NULL)
    {
	printf("%s\n", entry->d_name);
    }
    printf("\n");

    closedir(dir);


    /************************************/
    /* now, we are going to print out	*/
    /* how long a file has not been	*/
    /* modified.			*/
    /************************************/
    s = stat("/home/shay/g/ee469/labs/01/example.c", &statptr);

    last_modified_time = statptr.st_mtime;
    gettimeofday(&tp, &tzp);
    current_time = tp.tv_sec;

    printf("The file example.c is not modified for %lu seconds.\n",
	    current_time - last_modified_time);
}