how to determine if an open file is NUL: or not

Hi,

I'm trying to determine if an open file that is passed to me is the

NUL: file or not.

On Unix, I do:

(once) open /dev/null, fstat, and save the st_dev and st_ino values

then, in my is_file_null (int fid) routine, I do an fstat() on the passed-in

file number, and compare the st_dev and st_ino values to /dev/null's.

On WinXP Pro SP2, fstat() seems to return the file number as st_dev

(manual implies that, at best, it should be returning the "disk number" :),

and 0 for st_ino.

Any suggestions

thanks!



Answer this question

how to determine if an open file is NUL: or not

  • Mike Allen Mc Donogh

    If you're using C, then I don't know what to suggest. :-)

    What does a null file represent I assumed it meant a file that does not exist, or failed to open.



  • miloush

    Re:

    google for nul, fstream

    ...that doesn't yield an apparent answer :)

    Perhaps some extra keywords as a clue

    If I was using C++, I could query the file handle for is_open, but I don't see any other attributes/fields that look useful (e.g., the rdbuf attribute/field is not documented as being NULL for the NUL: file, and there is no apparent is_null attribute/field).

    But...I prefer to avoid C++ ... 35+ years of productive high-level language programming experience (including object oriented programming before anyone could spell "C++") make me shy away from it, along with a desire to have what I'm writing be highly portable.

    I.e., I'm using basic C, not C++.

    Thanks,

    Stan

    sieler@allegro.com


  • Maksim

    Try using C++ file handling instead of using C. The header you need to google is fstream.



  • how to determine if an open file is NUL: or not