Jin^eLD's patch, mannol's changes and Jmanguy's getline() fix for OSX