Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Willers
KWSys
Commits
9a3f9799
Unverified
Commit
9a3f9799
authored
4 years ago
by
Dmitry Kalinkin
Browse files
Options
Downloads
Patches
Plain Diff
Directory: implement error reporting
parent
83118a93
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Directory.cxx
+31
-4
31 additions, 4 deletions
Directory.cxx
Directory.hxx.in
+3
-2
3 additions, 2 deletions
Directory.hxx.in
with
34 additions
and
6 deletions
Directory.cxx
+
31
−
4
View file @
9a3f9799
...
...
@@ -103,7 +103,7 @@ void Directory::Clear()
namespace
KWSYS_NAMESPACE
{
bool
Directory
::
Load
(
const
std
::
string
&
name
)
bool
Directory
::
Load
(
const
std
::
string
&
name
,
std
::
string
*
errorMessage
)
{
this
->
Clear
();
# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
...
...
@@ -146,7 +146,8 @@ bool Directory::Load(const std::string& name)
return
_findclose
(
srchHandle
)
!=
-
1
;
}
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
std
::
string
&
name
)
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
std
::
string
&
name
,
std
::
string
*
errorMessage
)
{
# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
...
...
@@ -192,6 +193,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
# include <sys/types.h>
# include <dirent.h>
# include <errno.h>
# include <string.h>
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
...
...
@@ -209,29 +212,46 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
namespace
KWSYS_NAMESPACE
{
bool
Directory
::
Load
(
const
std
::
string
&
name
)
bool
Directory
::
Load
(
const
std
::
string
&
name
,
std
::
string
*
errorMessage
)
{
this
->
Clear
();
errno
=
0
;
DIR
*
dir
=
opendir
(
name
.
c_str
());
if
(
!
dir
)
{
if
(
errorMessage
!=
nullptr
)
{
*
errorMessage
=
std
::
string
(
strerror
(
errno
));
}
return
false
;
}
errno
=
0
;
for
(
kwsys_dirent
*
d
=
readdir
(
dir
);
d
;
d
=
readdir
(
dir
))
{
this
->
Internal
->
Files
.
emplace_back
(
d
->
d_name
);
}
if
(
errno
!=
0
)
{
if
(
errorMessage
!=
nullptr
)
{
*
errorMessage
=
std
::
string
(
strerror
(
errno
));
}
return
false
;
}
this
->
Internal
->
Path
=
name
;
closedir
(
dir
);
return
true
;
}
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
std
::
string
&
name
)
unsigned
long
Directory
::
GetNumberOfFilesInDirectory
(
const
std
::
string
&
name
,
std
::
string
*
errorMessage
)
{
errno
=
0
;
DIR
*
dir
=
opendir
(
name
.
c_str
());
if
(
!
dir
)
{
if
(
errorMessage
!=
nullptr
)
{
*
errorMessage
=
std
::
string
(
strerror
(
errno
));
}
return
0
;
}
...
...
@@ -239,6 +259,13 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
for
(
kwsys_dirent
*
d
=
readdir
(
dir
);
d
;
d
=
readdir
(
dir
))
{
count
++
;
}
if
(
errno
!=
0
)
{
if
(
errorMessage
!=
nullptr
)
{
*
errorMessage
=
std
::
string
(
strerror
(
errno
));
}
return
false
;
}
closedir
(
dir
);
return
count
;
}
...
...
This diff is collapsed.
Click to expand it.
Directory.hxx.in
+
3
−
2
View file @
9a3f9799
...
...
@@ -35,7 +35,7 @@ public:
* in that directory. 0 is returned if the directory can not be
* opened, 1 if it is opened.
*/
bool Load(const std::string&);
bool Load(const std::string&
, std::string* errorMessage = nullptr
);
/**
* Return the number of files in the current directory.
...
...
@@ -46,7 +46,8 @@ public:
* Return the number of files in the specified directory.
* A higher performance static method.
*/
static unsigned long GetNumberOfFilesInDirectory(const std::string&);
static unsigned long GetNumberOfFilesInDirectory(
const std::string&, std::string* errorMessage = nullptr);
/**
* Return the file at the given index, the indexing is 0 based
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment