8 #ifndef INCL_evo_impl_sysio_dir_h     9 #define INCL_evo_impl_sysio_dir_h    12 #include <sys/types.h>    20     #if !defined(EVO_USE_READDIR_R)    21         #if (defined(__GNUC__) && __GNUC__ >= 6) || (defined(__clang_major__) && __clang_major__ >= 4)    22             #define EVO_USE_READDIR_R 0     // Use thread-safe readdir()    24             #define EVO_USE_READDIR_R 1     // Use thread-safe variation readdir_r() up until deprecated by glibc 2.24+    45     struct _finddata_t context;
    47     const char*        firstfile;
    62             const size_t pathlen = strlen(path);
    63             filepath = (
char*)::malloc(pathlen+3);
    64             memcpy(filepath, path, pathlen);
    65             memcpy(filepath+pathlen, 
"\\*", 3);
    68         handle = _findfirst(filepath, &context);
    73                 default:      err = 
EFail;     
break;
    78             firstfile = context.name;
    88         if (filepath != NULL) {
   105     bool read(TStr& entry) {
   107             if (firstfile != NULL) {
   108                 entry.set(firstfile);
   113                     if (_findnext(
handle, &context) != 0) {
   117                     if (context.name[0] == 
'.' &&
   118                          (context.name[1] == 
'\0' ||
   119                            (context.name[1] == 
'.' && context.name[2] == 
'\0')
   123                     entry.set(context.name);
   138     #if EVO_USE_READDIR_R   158                 case EACCES:  err = 
EAccess;   
break;
   161                 default:      err = 
EFail;     
break;
   165         #if EVO_USE_READDIR_R   167             buffer = (
char*)::malloc(offsetof(
struct dirent, d_name) + pathconf(path, _PC_NAME_MAX) + 1);
   175     #if EVO_USE_READDIR_R   176         if (buffer != NULL) {
   204         #if EVO_USE_READDIR_R   205             assert( buffer != NULL );
   206             struct dirent* result = NULL;
   207             if (::readdir_r(
handle, (
struct dirent*)buffer, &result) == 0 && result != NULL) {
   208                 entry = result->d_name;
   212             struct dirent* result = ::readdir(
handle);
   213             if (result != NULL) {
   214                 entry = result->d_name;
   228             const int fd = ::dirfd(
handle);
   229             return (fd >= 0 && ::fchdir(fd) == 0);
   235 #if EVO_USE_READDIR_R Permission denied. 
Definition: sys.h:1135
 
Error open(const char *path)
Open directory for reading. 
Definition: sysio_dir.h:152
 
Evo implementation detail for system portability – this is included by most Evo headers, include this via: include <evo/type.h>. 
 
void seek()
Seek to beginning of directory. 
Definition: sysio_dir.h:190
 
DIR * Handle
System directory handle. 
Definition: sysio_dir.h:134
 
Evo I/O streams and Console I/O. 
 
System directory reader (used internally). 
Definition: sysio_dir.h:40
 
Resource not found. 
Definition: sys.h:1137
 
No error. 
Definition: sys.h:1115
 
Error
General Evo error code stored in exceptions, or used directly when exceptions are disabled...
Definition: sys.h:1113
 
bool read(TStr &entry)
Read next directory entry. 
Definition: sysio_dir.h:202
 
SysDir()
Constructor. 
Definition: sysio_dir.h:137
 
Evo C++ Library namespace. 
Definition: alg.h:11
 
void close()
Close currently open directory, if any. 
Definition: sysio_dir.h:174
 
bool chdir()
Change current working directory to currently open directory. 
Definition: sysio_dir.h:226
 
Operation failed. 
Definition: sys.h:1124
 
Handle handle
System directory handle. 
Definition: sysio_dir.h:242
 
~SysDir()
Destructor. 
Definition: sysio_dir.h:145