+static bool CanReadICOOrCUR(wxInputStream *stream, wxUint16 resourceType)
+{
+ // It's ok to modify the stream position in this function.
+
+ if ( stream->IsSeekable() && stream->SeekI(0) == wxInvalidOffset )
+ {
+ return false;
+ }
+
+ ICONDIR iconDir;
+ if ( !stream->Read(&iconDir, sizeof(iconDir)) )
+ {
+ return false;
+ }
+
+ return !iconDir.idReserved // reserved, must be 0
+ && wxUINT16_SWAP_ON_BE(iconDir.idType) == resourceType // either 1 or 2
+ && iconDir.idCount; // must contain at least one image
+}
+