/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <locale.h>
#include <langinfo.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

/*
    dev_t       st_dev;     // ID of device containing file 
    ino_t       st_ino;     // inode number 
    mode_t      st_mode;    // protection 
    nlink_t     st_nlink;   // number of hard links 
    uid_t       st_uid;     // user ID of owner 
    gid_t       st_gid;     // group ID of owner 
    dev_t       st_rdev;    // device ID (if special file) 
    off_t       st_size;    // total size, in bytes 
    blksize_t   st_blksize; // blocksize for filesystem I/O 
    blkcnt_t    st_blocks;  // number of blocks allocated 
    time_t      st_atime;   // time of last access 
    time_t      st_mtime;   // time of last modification 
    time_t      st_ctime;   // time of last status change 
*/


int main() {

	DIR *dp;
	struct dirent *ep;

	char source_dir[256];
	printf ("Enter a source directory: ");
	scanf ("%s",source_dir);
	//gets (source_dir);
	printf ("You entered: %s\n",source_dir);

	char full_path[512];	
	int empty;

	dp = (opendir (source_dir));
	struct stat statbuf;
	long counter1 = 0;

	//if (dp != NULL) {

//while ((dp = readdir(dir)) != NULL) {

	//	while ((ep = readdir (dp)) != NULL){
			//if (ep->d_name[0] == '0'
			//counter1++;
		
			//printf("%s\n", ep->d_name);
			
			//empty = stat( ep->d_name, &statbuf);
			//continue;
			
			

//dirp = opendir(".");

	while (dp) {
    		//errno = 0;
		if ((ep = readdir(dp)) != NULL) {



			if( strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 ){
        			//continue;


				strcpy(full_path, source_dir);
				strcat(full_path, "/");
				strcat(full_path, ep->d_name);
				empty = stat( full_path, &statbuf);
				printf("%s", full_path);

				//counter1 = blksize_t st_blksize
				//blkcnt_t    st_blocks;
				//counter1 = statbuf.st_blksize * statbuf.st_blocks;			

				if(S_ISDIR(statbuf.st_mode)){
					printf(" Directory\n");
				}else{
					printf(" %9jd\n", statbuf.st_size);
				}
				//printf(" %9l\n", counter1);
			}


			//if(S_ISDIR(statbuf.st_mode)){
			//	printf(" DIR");
			//}
		//}
		//closedir(dp);
		}else{
			printf("error opening source directory!\n");
			return 1;
		}
		//closedir(ep);
	}
	closedir(dp);

return 0;
}
