Please don't use perror() here, as errno won't be meaningful at this point. Use fprintf(stderr, ...).