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
e44a2be8
Commit
e44a2be8
authored
May 05, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make BufferedFile::close public.
parent
cada26d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+18
-2
test/gtest-extra.h
test/gtest-extra.h
+6
-4
No files found.
test/gtest-extra-test.cc
View file @
e44a2be8
...
...
@@ -350,6 +350,21 @@ TEST(BufferedFileTest, CloseErrorInDtor) {
},
FormatSystemErrorMessage
(
EBADF
,
"cannot close file"
)
+
"
\n
"
);
}
TEST
(
BufferedFileTest
,
Close
)
{
BufferedFile
f
=
OpenFile
(
".travis.yml"
);
int
fd
=
fileno
(
f
.
get
());
f
.
close
();
EXPECT_TRUE
(
f
.
get
()
==
0
);
EXPECT_TRUE
(
IsClosed
(
fd
));
}
TEST
(
BufferedFileTest
,
CloseError
)
{
BufferedFile
f
=
OpenFile
(
".travis.yml"
);
close
(
fileno
(
f
.
get
()));
EXPECT_SYSTEM_ERROR_NOASSERT
(
f
.
close
(),
EBADF
,
"cannot close file"
);
EXPECT_TRUE
(
f
.
get
()
==
0
);
}
TEST
(
FileTest
,
DefaultCtor
)
{
File
f
;
EXPECT_EQ
(
-
1
,
f
.
descriptor
());
...
...
@@ -656,7 +671,8 @@ TEST(OutputRedirectTest, ErrorInDtor) {
write_dup
.
dup2
(
write_fd
);
// "undo" close or dtor of BufferedFile will fail
}
// TODO: compile both in C++11 & C++98 mode
#endif
// TODO: test retry on EINTR
#endif // FMT_USE_FILE_DESCRIPTORS
}
// namespace
test/gtest-extra.h
View file @
e44a2be8
...
...
@@ -114,8 +114,6 @@ class BufferedFile {
explicit
BufferedFile
(
std
::
FILE
*
f
)
:
file_
(
f
)
{}
void
close
();
public:
// Constructs a BufferedFile object which doesn't represent any file.
BufferedFile
()
FMT_NOEXCEPT
(
true
)
:
file_
(
0
)
{}
...
...
@@ -182,10 +180,14 @@ class BufferedFile {
}
#endif
// Closes the file.
void
close
();
// Returns the pointer to a FILE object representing this file.
std
::
FILE
*
get
()
const
{
return
file_
;
}
};
// A file.
// A file.
Closed file is represented by a File object with descriptor -1.
// Methods that are not declared with FMT_NOEXCEPT(true) may throw
// fmt::SystemError in case of failure. Note that some errors such as
// closing the file multiple times will cause a crash on Windows rather
...
...
@@ -277,7 +279,7 @@ class File {
// Returns the file descriptor.
int
descriptor
()
const
FMT_NOEXCEPT
(
true
)
{
return
fd_
;
}
// Closes the file
if its descriptor is not -1
.
// Closes the file.
void
close
();
// Attempts to read count bytes from the file into the specified buffer.
...
...
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