DSL
Directory.h
1 //@AUTOHEADER@BEGIN@
2 /***********************************************************************\
3 | Drift Standard Libraries v1.01 |
4 | Copyright 2010-2023 Drift Solutions / Indy Sams |
5 | Docs and more information available at https://www.driftsolutions.dev |
6 | This file released under the 3-clause BSD license, |
7 | see included DSL.LICENSE.TXT file for details. |
8 \***********************************************************************/
9 //@AUTOHEADER@END@
10 
11 #ifndef __DSL_DIRECTORY_H__
12 #define __DSL_DIRECTORY_H__
13 
14 #ifdef __GLIBC__
15  #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)
16  #warning "Old glibc, using readdir_r"
17  #define __DSL_USE_READDIR_R__ 1
18  #endif
19 #endif
20 
29 class DSL_API_CLASS Directory {
30 private:
31  union {
32  char * mDir;
33  wchar_t * wDir;
34  };
35  #if defined(WIN32)
36  HANDLE hFind;
37  union {
38  WIN32_FIND_DATAA wfdA;
39  WIN32_FIND_DATAW wfdW;
40  };
41  #else
42  DIR * hFind;
43  #if defined(__DSL_USE_READDIR_R__)
44  dirent * last_res;
45  #endif
46  #endif
47 
48 public:
49  Directory();
50  Directory(const char * dir);
51  Directory(const wchar_t * dir);
52  ~Directory();
53 
54  bool Open(const char * dir);
55  bool Open(const wchar_t * dir);
56 
63  bool Read(char * buf, unsigned long bufSize, bool * is_dir=NULL, int64 * size=NULL);
70  bool Read(wchar_t * buf, unsigned long bufSize, bool * is_dir = NULL, int64 * size = NULL);
71 
72  void Close();
73 };
74 
77 #endif // __DSL_DIRECTORY_H__