Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- char *FollowPath(char *path, char *output);
- int main(int argc, char *argv[])
- {
- char buf[4096];
- if(argc > 1)
- {
- for(int i=1;i<argc;i++)
- {
- FollowPath(argv[i], buf);
- printf("%s%s\n", argv[i], buf);
- }
- return 0;
- }
- char *line = NULL;
- size_t size = 0;
- size_t bytes = 0;
- while(bytes = getline(&line, &size, stdin) != -1) {
- line[strlen(line)-1] = '\0';
- FollowPath(line, buf);
- printf("%s%s\n", line, buf);
- buf[0] = '\0';
- }
- free(line);
- }
- char *FollowPath(char *path, char *output)
- {
- char buf[1024];
- ssize_t len;
- if ((len = readlink(path, buf, sizeof(buf)-1)) != -1)
- {
- buf[len] = '\0';
- sprintf(output, "%s -> %s", output, buf);
- return FollowPath(buf, output);
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment