[vlc-commits] "Improve" readdir_r() usage

Rémi Denis-Courmont git at videolan.org
Mon Oct 10 21:18:52 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Oct 10 22:18:41 2011 +0300| [be14e27798c77916ffe09811d0551b35a0b858ef] | committer: Rémi Denis-Courmont

"Improve" readdir_r() usage

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=be14e27798c77916ffe09811d0551b35a0b858ef
---

 src/posix/filesystem.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index f7c769d..1c26099 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -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);



More information about the vlc-commits mailing list