Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
74169e4b
Commit
74169e4b
authored
Sep 12, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a portable getpagesize() implementation
parent
1e9ca17b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
1 deletion
+42
-1
posix.cc
posix.cc
+13
-0
posix.h
posix.h
+4
-1
test/posix-test.cc
test/posix-test.cc
+24
-0
test/posix-test.h
test/posix-test.h
+1
-0
No files found.
posix.cc
View file @
74169e4b
...
...
@@ -222,3 +222,16 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
fd_
=
-
1
;
return
file
;
}
long
fmt
::
getpagesize
()
{
#ifdef _WIN32
SYSTEM_INFO
si
=
{};
GetSystemInfo
(
&
si
);
return
si
.
dwPageSize
;
#else
long
size
=
FMT_POSIX_CALL
(
sysconf
(
_SC_PAGESIZE
));
if
(
size
<
0
)
throw
SystemError
(
errno
,
"cannot get memory page size"
);
return
size
;
#endif
}
posix.h
View file @
74169e4b
...
...
@@ -320,7 +320,10 @@ class File {
// this File object from the file.
BufferedFile
fdopen
(
const
char
*
mode
);
};
}
// Returns the memory page size.
long
getpagesize
();
}
// namespace fmt
#if !FMT_USE_RVALUE_REFERENCES
namespace
std
{
...
...
test/posix-test.cc
View file @
74169e4b
...
...
@@ -56,6 +56,7 @@ int fileno_count;
std
::
size_t
read_nbyte
;
std
::
size_t
write_nbyte
;
bool
increase_file_size
;
bool
sysconf_error
;
}
#define EMULATE_EINTR(func, error_result) \
...
...
@@ -80,6 +81,15 @@ int test::fstat(int fd, struct stat *buf) {
buf
->
st_size
=
max_file_size
();
return
result
;
}
long
test
::
sysconf
(
int
name
)
{
long
result
=
::
sysconf
(
name
);
if
(
!
sysconf_error
)
return
result
;
// Simulate an error.
errno
=
EINVAL
;
return
-
1
;
}
#else
errno_t
test
::
sopen_s
(
int
*
pfh
,
const
char
*
filename
,
int
oflag
,
int
shflag
,
int
pmode
)
{
...
...
@@ -184,6 +194,20 @@ TEST(UtilTest, StaticAssert) {
// a compile-time error.
}
TEST
(
UtilTest
,
GetPageSize
)
{
#ifdef _WIN32
SYSTEM_INFO
si
=
{};
GetSystemInfo
(
&
si
);
EXPECT_EQ
(
si
.
dwPageSize
,
fmt
::
getpagesize
());
#else
EXPECT_EQ
(
sysconf
(
_SC_PAGESIZE
),
fmt
::
getpagesize
());
sysconf_error
=
true
;
EXPECT_SYSTEM_ERROR
(
fmt
::
getpagesize
(),
EINVAL
,
"cannot get memory page size"
);
sysconf_error
=
false
;
#endif
}
TEST
(
FileTest
,
OpenRetry
)
{
write_file
(
"test"
,
"there must be something here"
);
File
*
f
=
0
;
...
...
test/posix-test.h
View file @
74169e4b
...
...
@@ -45,6 +45,7 @@ typedef size_t size_t;
typedef
ssize_t
ssize_t
;
int
open
(
const
char
*
path
,
int
oflag
,
int
mode
);
int
fstat
(
int
fd
,
struct
stat
*
buf
);
long
sysconf
(
int
name
);
#else
typedef
unsigned
size_t
;
typedef
int
ssize_t
;
...
...
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