summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2016-04-21 15:30:14 +0200
committerZdenek Kabelac <zkabelac@redhat.com>2016-04-21 17:48:19 +0200
commit11dd36245450ed664c4a6bd177f17a8077c820a1 (patch)
treeb5e7fde24927a699c39bece73fc6c55251cc7f07
parent1134ab63240de66850c30fe1576bbb8b4f3e7052 (diff)
downloadlvm2-11dd36245450ed664c4a6bd177f17a8077c820a1.tar.gz
tests: GLIBC decided to obsolete readdir_r
Keep the code compilatible without warnings on newer glibc.
-rw-r--r--test/lib/brick-shelltest.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h
index be7c3feba..b48253b65 100644
--- a/test/lib/brick-shelltest.h
+++ b/test/lib/brick-shelltest.h
@@ -122,11 +122,17 @@ inline Listing listdir( std::string p, bool recurse = false, std::string prefix
Listing r;
dir d( p );
+#if !defined(__GLIBC__) || (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 23))
+ /* readdir_r is deprecated with newer GLIBC */
struct dirent entry, *iter = 0;
- int readerr;
-
- while ( (readerr = readdir_r( d.d, &entry, &iter )) == 0 && iter ) {
+ while ( (errno = readdir_r( d.d, &entry, &iter )) == 0 && iter ) {
std::string ename( entry.d_name );
+#else
+ struct dirent *entry;
+ errno = 0;
+ while ( (entry = readdir( d.d )) ) {
+ std::string ename( entry->d_name );
+#endif
if ( ename == "." || ename == ".." )
continue;
@@ -134,8 +140,10 @@ inline Listing listdir( std::string p, bool recurse = false, std::string prefix
if ( recurse ) {
struct stat64 stat;
std::string s = p + "/" + ename;
- if ( ::stat64( s.c_str(), &stat ) == -1 )
+ if ( ::stat64( s.c_str(), &stat ) == -1 ) {
+ errno = 0;
continue;
+ }
if ( S_ISDIR(stat.st_mode) ) {
Listing sl = listdir( s, true, prefix + ename + "/" );
for ( Listing::iterator i = sl.begin(); i != sl.end(); ++i )
@@ -146,7 +154,7 @@ inline Listing listdir( std::string p, bool recurse = false, std::string prefix
r.push_back( ename );
};
- if ( readerr != 0 )
+ if ( errno != 0 )
throw syserr( "error reading directory", p );
return r;