This partly reverts commit
41e76d11dff6dd9bc08bf829751f9634f32cdd38. I
removed the "superfluous" errno-handling, which in fact is needed. Turns
out pathconf() might leave errno unchanged.
Reported-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
{
int ret;
DIR *ent;
- struct dirent *buf = NULL, *de;
+ struct dirent *buf, *de;
char *file;
struct kmscon_module *mod;
struct dirent *tmp;
long name_max;
+ /* errno may be left unchanged, see pathconf(3p) */
+ errno = 0;
name_max = pathconf(path, _PC_NAME_MAX);
- if (name_max < 0)
- return -errno;
+ if (name_max < 0) {
+ if (errno)
+ return -errno;
+ else
+ return -EINVAL;
+ }
len = offsetof(struct dirent, d_name) + name_max + 1;
tmp = malloc(len);