Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <libgen.h>
- #include <limits.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main(int argc, char* argv[]) {
- char file_name[PATH_MAX];
- struct stat st;
- int64_t acc = 0;
- int64_t res = 0;
- while (fgets(file_name, sizeof(file_name), stdin) != NULL) {
- int last = strlen(file_name) - 1;
- file_name[last] = '\0';
- if (lstat(file_name, &st) != -1 && S_ISREG(st.st_mode)) {
- acc = access(file_name, X_OK);
- res = lstat(file_name, &st);
- if (acc == 0) {
- int fd = open(file_name, O_RDONLY);
- // FILE* fin = fopen(file_name, "rb");
- char buffer[PATH_MAX] = {0};
- uint32_t buf = 0;
- // fread(&buf, 4, 1, fin);
- read(fd, &buf, sizeof(buf));
- lseek(fd, 0, SEEK_SET);
- read(fd, buffer, PATH_MAX);
- // fclose(fin);
- close(fd);
- strtok(buffer, "\n");
- if ((buf != 0x464C457F) && (buffer[0] == '#') && (buffer[1] == '!')) {
- char temp[strlen(buffer) - 1];
- strcpy(temp, buffer + 2);
- temp[strlen(temp)] = '\0';
- if (strlen(temp) > 0) {
- int ac = access(temp, X_OK);
- if (ac != 0) {
- printf("%s\n", file_name);
- }
- } else {
- printf("%s\n", file_name);
- }
- } else {
- printf("%s\n", file_name);
- }
- } else {
- printf("%s\n", file_name);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement