Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <limits.h>
- #include <inttypes.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdbool.h>
- int main() {
- char file_name[PATH_MAX];
- uint64_t result = 0;
- struct stat st;
- char *nl;
- while (fgets(file_name, sizeof(file_name), stdin)) {
- nl = memchr(file_name, '\n', sizeof(file_name));
- if (nl) {
- *nl = '\0';
- }
- if (-1 != lstat(file_name, &st)) {
- if (S_ISLNK(st.st_mode)) {
- char new_path[PATH_MAX];
- realpath(file_name, new_path);
- printf("%s\n", new_path);
- }
- }
- if (S_ISREG(st.st_mode)) {
- char* new_file;
- char* link_to_ = "link_to_";
- new_file = malloc(strlen(file_name) + strlen(link_to_));
- strcpy(new_file, file_name);
- ssize_t sl = -1;
- for (int i = strlen(file_name) - 1; i >= 0; i--) {
- if (file_name[i] == '/') {
- sl = i;
- break;
- }
- }
- for (int i = 0; i < strlen(link_to_); i++) {
- new_file[sl + 1 + i] = link_to_[i];
- }
- for (int i = sl + 1; i < strlen(file_name); i++) {
- new_file[sl + strlen(link_to_) + i + 1] = file_name[i];
- }
- symlink(file_name, new_file);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement