Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <libgen.h>
- #include <limits.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main()
- {
- char name[PATH_MAX];
- 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 (-1 != lstat(name, &st) && S_ISLNK(st.st_mode)) {
- char actualpath[PATH_MAX];
- char* ptr;
- ptr = realpath(name, actualpath);
- printf("%s\n", actualpath);
- } else {
- if (-1 != lstat(name, &st) && S_ISREG(st.st_mode)) {
- char* pref = "link_to_";
- char new_name[PATH_MAX];
- for (int i = 0; i < strlen(pref); i++) {
- new_name[i] = pref[i];
- }
- for (int i = 0; i < strlen(name); i++) {
- new_name[i + strlen(pref)] = name[i];
- }
- symlink(name, new_name);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement