#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	int i;
	struct stat st;
	int fd;

	for (i=1; (i<argc); i++) {
		if (stat(argv[i], &st) == 0) {
			printf("stat OK\n");
			printf("- st_size = %u\n", st.st_size);
			printf("- st_size = %u\n", st.st_size);
			printf("- st_blocks = %u\n", st.st_blocks);
			printf("- st_blksize = %u\n", st.st_blksize);
			printf("- st_mtime = %u %s\n", st.st_mtime, asctime(localtime(&st.st_mtime)));
		}
		else printf("stat failed: %s\n", strerror(errno));

		fd = open(argv[i], O_RDONLY);
		if ((fd >= 0) && (fstat(fd, &st) == 0)) {
			printf("fstat OK\n");
			printf("- st_size = %u\n", st.st_size);
			printf("- st_size = %u\n", st.st_size);
			printf("- st_blocks = %u\n", st.st_blocks);
			printf("- st_blksize = %u\n", st.st_blksize);
			printf("- st_mtime = %u %s\n", st.st_mtime, asctime(localtime(&st.st_mtime)));
		}
		else printf("fstat failed: %s\n", strerror(errno));
	}

	return 0;
}

