Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main()
- {
- char name[1000];
- long long ans = 0;
- struct stat st;
- char* nl;
- while (fgets(name, sizeof(name), stdin)) {
- nl = memchr(name, '\n', sizeof(name));
- if (nl) {
- *nl = '\0';
- }
- if (0 == lstat(name, &st) && st.st_mode & S_IXUSR) {
- int in = open(name, O_RDONLY);
- ssize_t in_read;
- int cnt = 0;
- int flg1 = 0;
- int flg2 = 0;
- char in_byte;
- int flg = 0;
- while ((in_read = read(in, &in_byte, sizeof(in_byte))) > 0) {
- flg = 1;
- cnt += 1;
- if (in_byte != 127 && cnt == 1) {
- flg1 = 1;
- }
- if (in_byte != '#' && cnt == 1) {
- flg2 = 1;
- }
- if (in_byte != '!' && cnt == 2) {
- flg2 = 1;
- }
- if (in_byte != 69 && cnt == 2) {
- flg1 = 1;
- }
- if (in_byte != 76 && cnt == 3) {
- flg1 = 1;
- }
- if (in_byte != 70 && cnt == 4) {
- flg1 = 1;
- }
- }
- close(in);
- if (flg2 == 0) {
- printf("here");
- in = open(name, O_RDONLY);
- char _file[1000];
- cnt = 0;
- while ((in_read = read(in, &in_byte, sizeof(in_byte))) > 0) {
- cnt += 1;
- if (cnt > 3 && in_byte != '\n') {
- printf("%c", in_byte);
- _file[cnt - 4] = in_byte;
- } else
- break;
- }
- nl = memchr(_file, '\n', sizeof(_file));
- if (nl) {
- *nl = '\0';
- }
- if (0 == lstat(_file, &st) && st.st_mode & S_IXUSR) {
- flg2 = 0;
- } else
- flg2 = 1;
- close(in);
- }
- if ((flg1 == 1 && flg2 == 1) || flg == 0) {
- printf("%s", name);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement