Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to get a file's name from FILE* struct in C
- FILE *f = fopen ("foo.txt", "r");
- struct file_with_name {
- FILE *f;
- char *name; /* OR char name[MAX] */
- }
- char buf[PATH_MAX];
- snprintf(buf, sizeof buf, "/proc/self/fd/%d", fileno(f));
- readlink(buf, buf, sizeof buf);
Add Comment
Please, Sign In to add comment