/* This function get each file's size (in bytes) and add to totalkb variable...
 *
 * Return totalkb/1024 (bytes/1024 == kilobytes) which is the first line of ls long format
 * ($ls -l or $ls -la)
 *
 * This print:
 * $ls -l
 * total X	[Where 'X' is totalkb variable]
 */

#include"e1e-e5e.h"
#include<sys/stat.h>
#include<sys/types.h>

int get_kilobytes(int n, struct dirent **fls){
	struct stat foo;
	int totalkb= 0;
	int k;

	for(k=0; k < n; k++){
		stat(fls[k]->d_name, &foo);
		totalkb+= foo.st_size;
	}

	/* If any file is less than 1024 bytes, return 4Kb (I don't know why, but /bin/ls does) */
	return (((totalkb / 1024) < 1 )?4:(totalkb / 1024));
}
