Also fix handling of long extensions (more than 3 characters)
minor changes to remove need for C features unsupported by MS Visual C