Bazil
Bazil

Reputation: 11

Pass more than filename argument to stat()?

I'd like to know if it's possible (no matter why) to pass more than just a filename for existing file to stat() function, so it would not fail and return 0?

I mean like this:

struct stat mystat; char file[100];
...
if(stat(file, &mystat)==0){
//success
}

Is it possible to specify file as "existing-file_some_special_chars_maybe_some-text" and to stat() not fail on that?

Upvotes: 1

Views: 132

Answers (2)

Ido Weinstein
Ido Weinstein

Reputation: 1168

How about just creating a list of file names and feeding them to stat() one by one?

Upvotes: 0

Marc B
Marc B

Reputation: 360572

stat() works on filenames, so if you're passing in something that isn't a filename, you shouldn't be surprised that it fails. You can use fstat() to get information on whatever file a file handle is pointing to, but otherwise you're stuck with just filenames.

Upvotes: 1

Related Questions