check file pointer before read/write operations