]> git.sesse.net Git - vlc/commitdiff
"Improve" readdir_r() usage
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 10 Oct 2011 19:18:41 +0000 (22:18 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 10 Oct 2011 19:18:41 +0000 (22:18 +0300)
src/posix/filesystem.c

index f7c769d5c17dade9d69d9f03059fece5ad6f112b..1c26099327dd6cf69e1e79c05da78062bd9d01d7 100644 (file)
@@ -191,15 +191,15 @@ char *vlc_readdir( DIR *dir )
     char *path = NULL;
 
     long len = fpathconf (dirfd (dir), _PC_NAME_MAX);
-    if (len == -1)
-    {
 #ifdef NAME_MAX
+    /* POSIX says there shall we room for NAME_MAX bytes at all times */
+    if (/*len == -1 ||*/ len < NAME_MAX)
         len = NAME_MAX;
 #else
-        errno = ENOMEM;
-        return NULL; // OS is broken. There is no sane way to fix this.
+    /* OS is broken. Lets assume there is no files left. */
+    if (len == -1)
+        return NULL;
 #endif
-    }
     len += offsetof (struct dirent, d_name) + 1;
 
     struct dirent *buf = malloc (len);