Guest User

Untitled

a guest
Aug 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. How to get a file's name from FILE* struct in C
  2. FILE *f = fopen ("foo.txt", "r");
  3.  
  4. struct file_with_name {
  5. FILE *f;
  6. char *name; /* OR char name[MAX] */
  7. }
  8.  
  9. char buf[PATH_MAX];
  10. snprintf(buf, sizeof buf, "/proc/self/fd/%d", fileno(f));
  11. readlink(buf, buf, sizeof buf);
Add Comment
Please, Sign In to add comment