gogagum

Untitled

Nov 6th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <limits.h>
  6. #include <inttypes.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. int main() {
  11.     char file_name[PATH_MAX];
  12.     uint64_t result = 0;
  13.     struct stat st;
  14.     char *nl;
  15.     while (fgets(file_name, sizeof(file_name), stdin)) {
  16.         nl = memchr(file_name, '\n', sizeof(file_name));
  17.         if (nl) {
  18.             *nl = '\0';
  19.         }
  20.         if (-1 != lstat(file_name, &st)) {
  21.             if (S_ISREG(st.st_mode)) {
  22.                 result += st.st_size;
  23.             }
  24.         }
  25.     }
  26.     printf("%"PRIu64"\n", result);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment