Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1.  
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8.  
  9. int main()
  10. {
  11. char name[1000];
  12. long long ans = 0;
  13. struct stat st;
  14. char* nl;
  15. while (fgets(name, sizeof(name), stdin)) {
  16. nl = memchr(name, '\n', sizeof(name));
  17. if (nl) {
  18. *nl = '\0';
  19. }
  20. if (0 == lstat(name, &st) && st.st_mode & S_IXUSR) {
  21. int in = open(name, O_RDONLY);
  22. ssize_t in_read;
  23. int cnt = 0;
  24. int flg1 = 0;
  25. int flg2 = 0;
  26. char in_byte;
  27. int flg = 0;
  28. while ((in_read = read(in, &in_byte, sizeof(in_byte))) > 0) {
  29. flg = 1;
  30. cnt += 1;
  31. if (in_byte != 127 && cnt == 1) {
  32. flg1 = 1;
  33. }
  34. if (in_byte != '#' && cnt == 1) {
  35. flg2 = 1;
  36. }
  37. if (in_byte != '!' && cnt == 2) {
  38. flg2 = 1;
  39. }
  40. if (in_byte != 69 && cnt == 2) {
  41. flg1 = 1;
  42. }
  43. if (in_byte != 76 && cnt == 3) {
  44. flg1 = 1;
  45. }
  46. if (in_byte != 70 && cnt == 4) {
  47. flg1 = 1;
  48. }
  49. }
  50. close(in);
  51. if (flg2 == 0) {
  52. printf("here");
  53. in = open(name, O_RDONLY);
  54. char _file[1000];
  55. cnt = 0;
  56. while ((in_read = read(in, &in_byte, sizeof(in_byte))) > 0) {
  57. cnt += 1;
  58. if (cnt > 3 && in_byte != '\n') {
  59. printf("%c", in_byte);
  60. _file[cnt - 4] = in_byte;
  61. } else
  62. break;
  63. }
  64. nl = memchr(_file, '\n', sizeof(_file));
  65. if (nl) {
  66. *nl = '\0';
  67. }
  68. if (0 == lstat(_file, &st) && st.st_mode & S_IXUSR) {
  69. flg2 = 0;
  70. } else
  71. flg2 = 1;
  72. close(in);
  73. }
  74. if ((flg1 == 1 && flg2 == 1) || flg == 0) {
  75. printf("%s", name);
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement