[vlc-commits] commit: vlc_readdir: thread-safety fix ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sat Apr 17 16:56:45 CEST 2010


vlc/vlc-1.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Apr 17 17:43:59 2010 +0300| [8d86389f86b58b47b2fb9fdc75c954b331f2f267] | committer: Rémi Denis-Courmont 

vlc_readdir: thread-safety fix

Use readdir_r() instead of readdir().
(cherry picked from commit ed9336c9de1770273a0b0a05d0c727b3387ac11e)

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

 src/text/filesystem.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 34d03f4..ffb5908 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -322,12 +322,18 @@ char *vlc_readdir( DIR *dir )
     return FromWide (ent->d_name);
 #else
     struct dirent *ent;
-
-    ent = readdir( (DIR *)dir );
-    if( ent == NULL )
+    struct
+    {
+        struct dirent ent;
+        char buf[NAME_MAX + 1];
+    } buf;
+    int val = readdir_r (dir, &buf.ent, &ent);
+    if (val)
+    {
+        errno = val;
         return NULL;
-
-    return vlc_fix_readdir( ent->d_name );
+    }
+    return ent ? vlc_fix_readdir( ent->d_name ) : NULL;
 #endif
 }
 



More information about the vlc-commits mailing list