• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Can you get the filename of a file opened with fopen?

Hi.  Is it possible to get the filename of a file that has been opened with fopen?  In other words, I have a global FILE pointer.  It gets opened in main().  Later, I want to be able to get the filename associated with it.  Can I use the file pointer to get it, or do I need to save the filename in memory?

Thanks.
0
mromeo
Asked:
mromeo
  • 2
  • 2
1 Solution
 
keteracelCommented:
unfortunately not.... I've hacked the include files on linux and the filename is not included anywhere. Why can't you just globally store the filename when you globally store the file?
0
 
mromeoAuthor Commented:
I can, but didn't want to do that if it wasn't necessary. The program is hefty to begin with and keeping memory allocation to a minimum is desirable.  Thanks for your info.
0
 
keteracelCommented:
do you actually need the filename anyway?
0
 
mromeoAuthor Commented:
I'm trying to remove the TOP portion of the file.  So I'm reading the bottom portion of the file, saving it to a buffer, removing the original file (with unlink -- which is where the filename comes in) and writing the buffer out to a new file with the same file name.  Can you think of a more efficient way of doing it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now