SHARE
TWEET

Untitled

a guest Nov 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fcntl.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <limits.h>
  7. #include <inttypes.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <stdbool.h>
  11. int main() {
  12.  
  13.     char file_name[PATH_MAX];
  14.     uint64_t result = 0;
  15.     struct stat st;
  16.     char *nl;
  17.     while (fgets(file_name, sizeof(file_name), stdin)) {
  18.         nl = memchr(file_name, '\n', sizeof(file_name));
  19.         if (nl) {
  20.             *nl = '\0';
  21.         }
  22.         if (-1 != lstat(file_name, &st)) {
  23.             if (S_ISLNK(st.st_mode)) {
  24.                 char new_path[PATH_MAX];
  25.                 realpath(file_name, new_path);
  26.                 printf("%s\n", new_path);
  27.             }
  28.         }
  29.         if (S_ISREG(st.st_mode)) {
  30.             char* new_file;
  31.             char* link_to_ = "link_to_";
  32.             new_file = malloc(strlen(file_name) + strlen(link_to_));
  33.             strcpy(new_file, file_name);
  34.             ssize_t sl = -1;
  35.             for (int i = strlen(file_name) - 1; i >= 0; i--) {
  36.                 if (file_name[i] == '/') {
  37.                     sl = i;
  38.                     break;
  39.                 }
  40.             }
  41.             for (int i = 0; i < strlen(link_to_); i++) {
  42.                 new_file[sl + 1 + i] = link_to_[i];
  43.             }
  44.             for (int i = sl + 1; i < strlen(file_name); i++) {
  45.                 new_file[sl + strlen(link_to_) + i + 1] = file_name[i];
  46.             }
  47.             symlink(file_name, new_file);
  48.  
  49.  
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top