#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

/*
 * Ohjelma hyvaksyy komentorivilla tiedoston nimen.
 * Tulostaa tiedoston nimen ja unix modifikointiajan ja tiedoston koon.
 * 
 * Idea on etsia tiedostot jotka ovat muuttuneet kahden ajokerran valilla.
 * 
 * Kaanna ensin ohjelma:
 * gcc -Wall -O2 -o fileinfo fileinfo.c
 * 
 * Kaytto: 
 * 
 * 1. find / -type f -exec ./fileinfo {} ";" >/tmp/files.tmp
 * 2. sort -u < /tmp/files.tmp > /tmp/files.txt
 * 3. rm /tmp/files.tmp
 * 4. tee muutoksia, kopioi tiedostoja ym.
 * 5. find / -type f -exec ./fileinfo {} ";" >/tmp/files.tmp
 * 6. sort -u < /tmp/files.tmp > /tmp/files2.txt
 * 7. rm /tmp/files.tmp
 * 8. diff /tmp/files.txt /tmp/files2.txt
 * 
 * Tulos on luettelo tiedostoista jotka ovat muuttuneet seka uudet tiedostot.
 * 
 */

int main(int argc, char ** argv) {
	struct stat stats;
	if (argc < 2) {
		fprintf(stderr, "*** ERROR: No file specified.\n");
		return -1;
	}
	if (lstat(argv[1], &stats) == -1) {
		fprintf(stderr, "*** ERROR: Couldn't access file '%s': %s.\n", argv[1], strerror(errno));
		return -1;
	}
	fprintf(stdout, "%s  %lu  %lu\n", argv[1], stats.st_mtime, stats.st_size);
	return 0;
}


