Hello, Is this possible to know the name of a file with it's file descriptor ?
Thanks
file name <- file descriptor
-
- Posts: 13
- Joined: Fri Jan 06, 2006 5:44 pm
Re: file name <- file descriptor
...why?johnmph wrote:Hello, Is this possible to know the name of a file with it's file descriptor ?
Thanks
If you've got a file descriptor, you know the file name. You had to know the file name to open a descriptor to it.
Chances are you're trying to do something you don't won't *really* want to do, or you're going about doing it the wrong way.
None-the-less, if you still want to go for it, give fstat() a try. Between fstat, and some direct.h work,(specifcally, opendir(), and recursing through the dir, trying to match the file inode returned by fstat with an inode in a structure returned from opendir() ) you could get it done. It wouldn't be simple, or proper, or even smiled upon, and in the end, there is a severe deficit of reasons to do such an operation, but if you're talented enough to string together the commands outlined above to working code, then I'm going to assume you're intelligent enough to know why this is a "bad idea", and that you've got a good reason for it.
Perhaps, however, if that's not the case, you instead explain the situation you're in, and what you want to *ultimately* acomplish. Too many times people ask very pointed, complicated questions, when the same result can be determined by a simple alternative.
Re: file name <- file descriptor
Thank you for fstat / opendir solution and obviously, I don't have access to the file name.DustinFraze wrote:...why?johnmph wrote:Hello, Is this possible to know the name of a file with it's file descriptor ?
Thanks
If you've got a file descriptor, you know the file name. You had to know the file name to open a descriptor to it.
Chances are you're trying to do something you don't won't *really* want to do, or you're going about doing it the wrong way.
None-the-less, if you still want to go for it, give fstat() a try. Between fstat, and some direct.h work,(specifcally, opendir(), and recursing through the dir, trying to match the file inode returned by fstat with an inode in a structure returned from opendir() ) you could get it done. It wouldn't be simple, or proper, or even smiled upon, and in the end, there is a severe deficit of reasons to do such an operation, but if you're talented enough to string together the commands outlined above to working code, then I'm going to assume you're intelligent enough to know why this is a "bad idea", and that you've got a good reason for it.
Perhaps, however, if that's not the case, you instead explain the situation you're in, and what you want to *ultimately* acomplish. Too many times people ask very pointed, complicated questions, when the same result can be determined by a simple alternative.