Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move lsdir.h to a new 'common' module
- Loading branch information
1 parent
702ddf7
commit 4f63ec9
Showing
6 changed files
with
127 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# top-level folders | ||
/build | ||
/.vscode | ||
|
||
# file types | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "lsdir.h" | ||
|
||
#ifdef __GNUC__ | ||
|
||
lsdir::lsdir(const char* directory) | ||
{ | ||
dir = opendir(directory); | ||
} | ||
|
||
lsdir::~lsdir() | ||
{ | ||
if (dir) | ||
{ | ||
closedir(dir); | ||
} | ||
} | ||
|
||
const char* lsdir::next() | ||
{ | ||
struct dirent *dp = dir ? readdir(dir) : nullptr; | ||
return dp ? dp->d_name : nullptr; | ||
} | ||
|
||
// end __GNUC__ | ||
#elif defined(_MSC_VER) | ||
|
||
lsdir::lsdir(const char* directory) | ||
{ | ||
char* buf = new char[strlen(directory) + 4]; | ||
strcpy(buf, directory); | ||
strcat(buf, "\\*"); | ||
|
||
hFile = _findfirst(buf, &filedata); | ||
first = true; | ||
delete[] buf; | ||
} | ||
|
||
lsdir::~lsdir() | ||
{ | ||
if (hFile != -1) | ||
{ | ||
_findclose(hFile); | ||
} | ||
} | ||
|
||
const char* lsdir::next() | ||
{ | ||
if (hFile == -1) | ||
{ | ||
return nullptr; | ||
} | ||
if (first) | ||
{ | ||
first = false; | ||
return filedata.name; | ||
} | ||
if (_findnext(hFile, &filedata) != 0) | ||
{ | ||
_findclose(hFile); | ||
hFile = -1; | ||
return nullptr; | ||
} | ||
return filedata.name; | ||
} | ||
|
||
#endif // _MSC_VER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef LSDIR_H | ||
#define LSDIR_H | ||
|
||
#ifdef __GNUC__ | ||
#include <dirent.h> | ||
|
||
class lsdir | ||
{ | ||
DIR* dir; | ||
|
||
public: | ||
explicit lsdir(const char* directory); | ||
~lsdir(); | ||
const char* next(); | ||
|
||
private: | ||
lsdir(const lsdir&) = delete; | ||
lsdir(lsdir&&) = delete; | ||
lsdir& operator=(const lsdir&) = delete; | ||
lsdir& operator=(lsdir&&) = delete; | ||
}; | ||
|
||
// end __GNUC__ | ||
#elif defined(_MSC_VER) | ||
#include <io.h> | ||
|
||
class lsdir | ||
{ | ||
long hFile; | ||
struct _finddata_t filedata; | ||
bool first; | ||
|
||
public: | ||
explicit lsdir(const char* directory); | ||
~lsdir(); | ||
const char* next(); | ||
|
||
private: | ||
lsdir(const lsdir&) = delete; | ||
lsdir(lsdir&&) = delete; | ||
lsdir& operator=(const lsdir&) = delete; | ||
lsdir& operator=(lsdir&&) = delete; | ||
}; | ||
|
||
#endif // _MSC_VER | ||
#endif // LSDIR_H |
This file was deleted.
Oops, something went wrong.