vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Jan 27 18:25:47 2014 +0200| [7625fc4bd47f1e1220d31a4ff964003e6924c85a] | committer: Rémi Denis-Courmont
vlc_readdir: drop support for threaded access to a single DIR This simplifies the code and avoids the controversial readdir_r() function. None of the vlc_readdir() or vlc_loaddir() code paths shared the directory handle with another thread anyway. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7625fc4bd47f1e1220d31a4ff964003e6924c85a --- src/posix/filesystem.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c index b008a6c..afb132b 100644 --- a/src/posix/filesystem.c +++ b/src/posix/filesystem.c @@ -142,7 +142,8 @@ DIR *vlc_opendir (const char *dirname) /** * Reads the next file name from an open directory. * - * @param dir The directory that is being read + * @param dir directory handle as returned by vlc_opendir() + * (must not be used by another thread concurrently) * * @return a UTF-8 string of the directory entry. Use free() to release it. * If there are no more entries in the directory, NULL is returned. @@ -150,29 +151,8 @@ DIR *vlc_opendir (const char *dirname) */ char *vlc_readdir( DIR *dir ) { - /* Beware that readdir_r() assumes <buf> is large enough to hold the result - * dirent including the file name. A buffer overflow could occur otherwise. - * In particular, pathconf() and _POSIX_NAME_MAX cannot be used here. */ - struct dirent *ent; - char *path = NULL; - - long len = fpathconf (dirfd (dir), _PC_NAME_MAX); - /* POSIX says there shall be room for NAME_MAX bytes at all times */ - if (len == -1 || len < NAME_MAX) - len = NAME_MAX; - len += sizeof (*ent) + 1 - sizeof (ent->d_name); - - struct dirent *buf = malloc (len); - if (unlikely(buf == NULL)) - return NULL; - - int val = readdir_r (dir, buf, &ent); - if (val != 0) - errno = val; - else if (ent != NULL) - path = strdup (ent->d_name); - free (buf); - return path; + struct dirent *ent = readdir (dir); + return (ent != NULL) ? strdup (ent->d_name) : NULL; } /** _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
