according to a hint from another thread I want to analyze pointers, if their dereferencing would cause an segmentation faults or not. The idea is to write code like this:
bool IsPointerValid( void* pPointer )
{
// when opening "/tmp/hugo" here, it works fine... but not with /dev/null??
int iFD = open( "/dev/null", O_WRONLY );
int iBytesWritten = write( iFD, pPointer, 4 );
close( iFD );
return iBytesWritten > 0;
}
But whatevery I pass to IsPointerValid(..)
, it returns always true - because iBytesWritten
is always 4
. But when opening "/tmp/testfile"
or a fifo, it works like expected: Passing the NULL pointer to write(..)
, it returns -1
.
What is the reason for this special treating of "/dev/null"
?
Thanks,
Charly