SHARE
TWEET

Untitled

a guest Nov 19th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fcntl.h>
  2. #include <libgen.h>
  3. #include <limits.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/stat.h>
  8. #include <sys/types.h>
  9. #include <unistd.h>
  10.  
  11. int main()
  12. {
  13.     char name[PATH_MAX];
  14.     long long ans = 0;
  15.     struct stat st;
  16.     char* nl;
  17.     while (fgets(name, sizeof(name), stdin)) {
  18.         nl = memchr(name, '\n', sizeof(name));
  19.         if (nl) {
  20.             *nl = '\0';
  21.         }
  22.         if (-1 != lstat(name, &st) && S_ISLNK(st.st_mode)) {
  23.             char actualpath[PATH_MAX];
  24.             char* ptr;
  25.             ptr = realpath(name, actualpath);
  26.             printf("%s\n", actualpath);
  27.         } else {
  28.             if (-1 != lstat(name, &st) && S_ISREG(st.st_mode)) {
  29.                 char* pref = "link_to_";
  30.                 char new_name[PATH_MAX];
  31.                 for (int i = 0; i < strlen(pref); i++) {
  32.                     new_name[i] = pref[i];
  33.                 }
  34.                 for (int i = 0; i < strlen(name); i++) {
  35.                     new_name[i + strlen(pref)] = name[i];
  36.                 }
  37.                 symlink(name, new_name);
  38.             }
  39.         }
  40.     }
  41. }
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