Advertisement
rudolf222222

Untitled

Dec 1st, 2022 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <libgen.h>
  3. #include <limits.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <sys/stat.h>
  9. #include <sys/types.h>
  10. #include <unistd.h>
  11.  
  12. int main(int argc, char* argv[]) {
  13.   char file_name[PATH_MAX];
  14.   struct stat st;
  15.   int64_t acc = 0;
  16.   int64_t res = 0;
  17.   while (fgets(file_name, sizeof(file_name), stdin) != NULL) {
  18.     int last = strlen(file_name) - 1;
  19.     file_name[last] = '\0';
  20.     if (lstat(file_name, &st) != -1 && S_ISREG(st.st_mode)) {
  21.       acc = access(file_name, X_OK);
  22.       res = lstat(file_name, &st);
  23.       if (acc == 0) {
  24.         int fd = open(file_name, O_RDONLY);
  25.         // FILE* fin = fopen(file_name, "rb");
  26.         char buffer[PATH_MAX] = {0};
  27.         uint32_t buf = 0;
  28.         // fread(&buf, 4, 1, fin);
  29.         read(fd, &buf, sizeof(buf));
  30.         lseek(fd, 0, SEEK_SET);
  31.         read(fd, buffer, PATH_MAX);
  32.         // fclose(fin);
  33.         close(fd);
  34.         strtok(buffer, "\n");
  35.         if ((buf != 0x464C457F) && (buffer[0] == '#') && (buffer[1] == '!')) {
  36.           char temp[strlen(buffer) - 1];
  37.           strcpy(temp, buffer + 2);
  38.           temp[strlen(temp)] = '\0';
  39.           if (strlen(temp) > 0) {
  40.             int ac = access(temp, X_OK);
  41.             if (ac != 0) {
  42.               printf("%s\n", file_name);
  43.             }
  44.           } else {
  45.             printf("%s\n", file_name);
  46.           }
  47.         } else {
  48.           printf("%s\n", file_name);
  49.         }
  50.       } else {
  51.         printf("%s\n", file_name);
  52.       }
  53.     }
  54.   }
  55.   return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement