cxong / tinydir

Lightweight, portable and easy to integrate C directory and file reader
Other
803 stars 124 forks source link

Compile error with newer glibc version: readdir_r is deprecated #41

Closed susnux closed 8 years ago

susnux commented 8 years ago

Compiling with newer glibc versions will not work as readdir_r is deprecated. It will lead into this errors:

tinydir/tinydir.h:241:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations] error = readdir_r(dir->_d, dir->_ep, &dir->_e); ^~~~~ tinydir/tinydir.h:377:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations] if (readdir_r(dir->_d, dir->_ep, &dir->_e) != 0) ^~

It is recommended to use readdir instead of readdir_r and use external locking (e.g. implement a simple mutex) until a new POSIX version is release which requires readdir to be thread-safe. See also the "Portability Note" of readdir_r in [2]. The OLA project encountered the same issue [0], for reasons why to use readdir instead of readdir_r see also [1].

Some references: [0] https://github.com/OpenLightingProject/ola/issues/1055 [1] https://womble.decadent.org.uk/readdir_r-advisory.html [2] https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html