Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <limits.h>
- #include <stddef.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <string.h>
- #include <string.h>
- int main (int argc, char * argv[])
- {
- long long sum_size = 0;
- long long max_size = 0;
- char max_name[500] = {'\0'};
- char *p;
- long long max_sum_size = strtol(argv[2], &p, 10);
- struct dirent *ep;
- DIR *dp = opendir(argv[1]);
- if (dp != NULL) {
- ep = readdir(dp);
- while (ep != NULL) {
- struct stat buffer;
- char file_path[PATH_MAX + 1];
- sprintf(file_path, "%s/%s", argv[1], ep->d_name);
- int status = stat(file_path, &buffer);
- if (status == 0) {
- //регулярный файл?
- if (S_ISREG(buffer.st_mode) && !S_ISLNK(buffer.st_mode)) {
- sum_size += buffer.st_size;
- if (buffer.st_size > max_size) {
- max_size = buffer.st_size;
- strcpy(max_name, ep->d_name);
- } else if (buffer.st_size == max_size &&
- strcmp(ep->d_name, max_name) < 0) {
- strcpy(max_name, ep->d_name);
- }
- }
- }
- ep = readdir(dp);
- }
- closedir(dp);
- }
- if (sum_size > max_sum_size) {
- printf("%s", max_name);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement