Implement isValidFilenameImpl

I've implemented it exactly like the C native.