/* Check if the actions of the rule needs to be evaluated. Return 0 if
   the actions should be executed, and return 1 otherwise.

   Precondition: the file associated with the rule's target name exists
                 and the rule has dependencies
 */
int check_dep_time(Rule *rule) {
    struct stat target_stat;
    if (stat(rule->target, &target_stat) != 0) {
        perror("stat");
        exit(1);
    }
    Dependency *curr_dependency = rule->dependencies;
    while (curr_dependency != NULL) {
        struct stat dep_stat;
        if (stat(rule->target, &dep_stat) != 0) {
            perror("stat");
            exit(1);
        }
        if (compare_time(target_stat.st_mtim, dep_stat.st_mtim) == 0) {
            return 0;
        }
        curr_dependency = curr_dependency->next_dep;
    }
    return 1;
}

/* Compare the modification time of the target file with a dependency
   file. If the time of the dependency file is newer than that of the 
   target, return 0; otherwise, return 1.
 */
int compare_time(struct timespec target_st_mtim, struct timespec dep_st_mtim) {
    // Check the second part
    if (target_st_mtim.tv_sec > dep_st_mtim.tv_sec) {
        return 1;
    } else if (target_st_mtim.tv_sec < dep_st_mtim.tv_sec) {
        return 0;
    } else {   // Check the nanosecond part
        if (target_st_mtim.tv_nsec < dep_st_mtim.tv_nsec) {
            return 0;
        } else {
            return 1;
        }
    }
}
st_mtim should give me the time of the modification time of the file, but the value I get is not. 