Advertisement
Guest User

belmo.c

a guest
Dec 7th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <time.h>
  9.  
  10. void cls()
  11. {
  12.     system("clear");
  13. }
  14.  
  15. struct f_info
  16. {
  17.     char *ext;
  18.     size_t size;
  19. };
  20.  
  21. struct f_info *f_file(const char *pname)
  22. {
  23.     char *name = malloc(32);
  24.     struct f_info *info = malloc(sizeof(struct f_info));
  25.     info->ext = malloc(8);
  26.     strcpy(name, pname);
  27.     int i=0; while (name[i] != '.' && name[i]) i++;
  28.     i++;
  29.     strncpy(info->ext, name+i, 4);
  30.     struct stat st;
  31.     if (lstat(name, &st) < 0) info->size = 0;
  32.     else info->size = st.st_size;
  33.     return info;
  34. }
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39.     if (argc != 2) return -1;
  40.     cls();
  41.     struct f_info *r = f_file(argv[1]);
  42.     if (r)
  43.         printf("extension : %s\tsize : %zu\n", r->ext, r->size);
  44.     puts("/bin/sh");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement