Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d09b8b5b
Commit
d09b8b5b
authored
Feb 28, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/FileInfo: use GetFileAttributesEx() on WIN32
parent
ee327db5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
1 deletion
+49
-1
FileInfo.hxx
src/fs/FileInfo.hxx
+49
-1
No files found.
src/fs/FileInfo.hxx
View file @
d09b8b5b
...
...
@@ -25,7 +25,29 @@
#include "util/Error.hxx"
#include <stdint.h>
#ifdef WIN32
#include <fileapi.h>
#else
#include <sys/stat.h>
#endif
#ifdef WIN32
static
inline
constexpr
uint64_t
ConstructUint64
(
DWORD
lo
,
DWORD
hi
)
{
return
uint64_t
(
lo
)
|
(
uint64_t
(
hi
)
<<
32
);
}
static
constexpr
time_t
FileTimeToTimeT
(
FILETIME
ft
)
{
return
(
ConstructUint64
(
ft
.
dwLowDateTime
,
ft
.
dwHighDateTime
)
-
116444736000000000
)
/
10000000
;
}
#endif
class
FileInfo
{
friend
bool
GetFileInfo
(
Path
path
,
FileInfo
&
info
,
...
...
@@ -33,23 +55,43 @@ class FileInfo {
friend
bool
GetFileInfo
(
Path
path
,
FileInfo
&
info
,
Error
&
error
);
#ifdef WIN32
WIN32_FILE_ATTRIBUTE_DATA
data
;
#else
struct
stat
st
;
#endif
public
:
bool
IsRegular
()
const
{
#ifdef WIN32
return
data
.
dwFileAttributes
&
FILE_ATTRIBUTE_NORMAL
;
#else
return
S_ISREG
(
st
.
st_mode
);
#endif
}
bool
IsDirectory
()
const
{
#ifdef WIN32
return
data
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
;
#else
return
S_ISDIR
(
st
.
st_mode
);
#endif
}
uint64_t
GetSize
()
const
{
#ifdef WIN32
return
ConstructUint64
(
data
.
nFileSizeLow
,
data
.
nFileSizeHigh
);
#else
return
st
.
st_size
;
#endif
}
time_t
GetModificationTime
()
const
{
#ifdef WIN32
return
FileTimeToTimeT
(
data
.
ftLastWriteTime
);
#else
return
st
.
st_mtime
;
#endif
}
#ifndef WIN32
...
...
@@ -76,7 +118,8 @@ GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true)
{
#ifdef WIN32
(
void
)
follow_symlinks
;
return
stat
(
path
.
c_str
(),
&
info
.
st
)
==
0
;
return
GetFileAttributesEx
(
path
.
c_str
(),
GetFileExInfoStandard
,
&
info
.
data
);
#else
int
ret
=
follow_symlinks
?
stat
(
path
.
c_str
(),
&
info
.
st
)
...
...
@@ -91,7 +134,12 @@ GetFileInfo(Path path, FileInfo &info, bool follow_symlinks, Error &error)
bool
success
=
GetFileInfo
(
path
,
info
,
follow_symlinks
);
if
(
!
success
)
{
const
auto
path_utf8
=
path
.
ToUTF8
();
#ifdef WIN32
error
.
FormatLastError
(
"Failed to access %s"
,
path_utf8
.
c_str
());
#else
error
.
FormatErrno
(
"Failed to access %s"
,
path_utf8
.
c_str
());
#endif
}
return
success
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment