(Harmless but confusing) Why are you checking ENOENT here ?  The man page for fgetgrent() says nothing about setting that (only ENOMEM); and, if fopen() set it, we already returned anyway.