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
a2bf6bb3
Commit
a2bf6bb3
authored
8 years ago
by
Mathieu Westphal (Kitware)
Committed by
Brad King
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
SystemTools: Add cross-platform stat() wrapper
parent
7e9f7b7b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
SystemTools.cxx
+27
-1
27 additions, 1 deletion
SystemTools.cxx
SystemTools.hxx.in
+20
-0
20 additions, 0 deletions
SystemTools.hxx.in
testSystemTools.cxx
+13
-0
13 additions, 0 deletions
testSystemTools.cxx
with
60 additions
and
1 deletion
SystemTools.cxx
+
27
−
1
View file @
a2bf6bb3
...
...
@@ -54,7 +54,6 @@
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<sys/stat.h>
#include
<time.h>
#if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__)
...
...
@@ -1257,6 +1256,33 @@ bool SystemTools::TestFileAccess(const std::string& filename,
#endif
}
//----------------------------------------------------------------------------
int
SystemTools
::
Stat
(
const
char
*
path
,
SystemTools
::
Stat_t
*
buf
)
{
if
(
!
path
)
{
errno
=
EFAULT
;
return
-
1
;
}
return
SystemTools
::
Stat
(
std
::
string
(
path
),
buf
);
}
//----------------------------------------------------------------------------
int
SystemTools
::
Stat
(
const
std
::
string
&
path
,
SystemTools
::
Stat_t
*
buf
)
{
if
(
path
.
empty
())
{
errno
=
ENOENT
;
return
-
1
;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
// Ideally we should use ConvertToWindowsExtendedPath to support
// long paths, but _wstat64 rejects paths with '?' in them, thinking
// they are wildcards.
return
_wstat64
(
Encoding
::
ToWide
(
path
).
c_str
(),
buf
);
#else
return
stat
(
path
.
c_str
(),
buf
);
#endif
}
//----------------------------------------------------------------------------
#ifdef __CYGWIN__
bool
SystemTools
::
PathCygwinToWin32
(
const
char
*
path
,
char
*
win32_path
)
...
...
This diff is collapsed.
Click to expand it.
SystemTools.hxx.in
+
20
−
0
View file @
a2bf6bb3
...
...
@@ -13,6 +13,9 @@
#include <@KWSYS_NAMESPACE@/String.hxx>
#include <sys/types.h>
// include sys/stat.h after sys/types.h
#include <sys/stat.h>
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h> // For access permissions for use with access()
#endif
...
...
@@ -324,6 +327,23 @@ public:
TestFilePermissions permissions);
static bool TestFileAccess(const std::string& filename,
TestFilePermissions permissions);
/**
* Cross platform wrapper for stat struct
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
typedef struct _stat64 Stat_t;
#else
typedef struct stat Stat_t;
#endif
/**
* Cross platform wrapper for stat system call
*
* On Windows this may not work for paths longer than 250 characters
* due to limitations of the underlying '_wstat64' call.
*/
static int Stat(const char* path, Stat_t* buf);
static int Stat(const std::string& path, Stat_t* buf);
/**
* Converts Cygwin path to Win32 path. Uses dictionary container for
...
...
This diff is collapsed.
Click to expand it.
testSystemTools.cxx
+
13
−
0
View file @
a2bf6bb3
...
...
@@ -135,6 +135,19 @@ static bool CheckFileOperations()
res
=
false
;
}
kwsys
::
SystemTools
::
Stat_t
buf
;
if
(
kwsys
::
SystemTools
::
Stat
(
testTxtFile
.
c_str
(),
&
buf
)
!=
0
)
{
std
::
cerr
<<
"Problem with Stat - unable to stat text file: "
<<
testTxtFile
<<
std
::
endl
;
res
=
false
;
}
if
(
kwsys
::
SystemTools
::
Stat
(
testBinFile
,
&
buf
)
!=
0
)
{
std
::
cerr
<<
"Problem with Stat - unable to stat bin file: "
<<
testBinFile
<<
std
::
endl
;
res
=
false
;
}
if
(
!
kwsys
::
SystemTools
::
MakeDirectory
(
testNewDir
))
{
std
::
cerr
<<
"Problem with MakeDirectory for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
...
...
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