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
8214a5ef
Commit
8214a5ef
authored
May 03, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MSVC build.
parent
1a2d7be3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
test/gtest-extra.cc
test/gtest-extra.cc
+11
-15
test/gtest-extra.h
test/gtest-extra.h
+3
-1
No files found.
test/gtest-extra.cc
View file @
8214a5ef
...
...
@@ -42,9 +42,6 @@
# define O_TRUNC _O_TRUNC
# define S_IRUSR _S_IREAD
# define S_IWUSR _S_IWRITE
# define close _close
# define dup _dup
# define dup2 _dup2
#endif // _WIN32
// Retries the expression while it evaluates to -1 and error equals to EINTR.
...
...
@@ -57,7 +54,7 @@ FileDescriptor::FileDescriptor(const char *path, int oflag) {
int
mode
=
S_IRUSR
|
S_IWUSR
;
#ifdef _WIN32
fd_
=
-
1
;
_sopen_s
(
&
fd
,
path
,
oflag
,
_SH_DENYNO
,
mode
);
_sopen_s
(
&
fd
_
,
path
,
oflag
,
_SH_DENYNO
,
mode
);
#else
FMT_RETRY
(
fd_
,
open
(
path
,
oflag
,
mode
));
#endif
...
...
@@ -70,13 +67,13 @@ void FileDescriptor::close() {
return
;
// Don't need to retry close in case of EINTR.
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
if
(
::
close
(
fd_
)
!=
0
)
if
(
::
FMT_POSIX
(
close
(
fd_
)
)
!=
0
)
fmt
::
ReportSystemError
(
errno
,
"cannot close file"
);
}
FileDescriptor
FileDescriptor
::
dup
(
int
fd
)
{
int
new_fd
=
0
;
FMT_RETRY
(
new_fd
,
::
dup
(
fd
));
FMT_RETRY
(
new_fd
,
::
FMT_POSIX
(
dup
(
fd
)
));
if
(
new_fd
==
-
1
)
fmt
::
ThrowSystemError
(
errno
,
"cannot duplicate file descriptor {}"
)
<<
fd
;
return
FileDescriptor
(
new_fd
);
...
...
@@ -84,7 +81,7 @@ FileDescriptor FileDescriptor::dup(int fd) {
void
FileDescriptor
::
dup2
(
int
fd
)
{
int
result
=
0
;
FMT_RETRY
(
result
,
::
dup2
(
fd_
,
fd
));
FMT_RETRY
(
result
,
::
FMT_POSIX
(
dup2
(
fd_
,
fd
)
));
if
(
result
==
-
1
)
{
fmt
::
ThrowSystemError
(
errno
,
"cannot duplicate file descriptor {} to {}"
)
<<
fd_
<<
fd
;
...
...
@@ -93,23 +90,22 @@ void FileDescriptor::dup2(int fd) {
void
FileDescriptor
::
dup2
(
int
fd
,
ErrorCode
&
ec
)
FMT_NOEXCEPT
(
true
)
{
int
result
=
0
;
FMT_RETRY
(
result
,
::
dup2
(
fd_
,
fd
));
FMT_RETRY
(
result
,
::
FMT_POSIX
(
dup2
(
fd_
,
fd
)
));
if
(
result
==
-
1
)
ec
=
ErrorCode
(
errno
);
}
void
FileDescriptor
::
pipe
(
FileDescriptor
&
read
_fd
,
FileDescriptor
&
write_fd
)
{
void
FileDescriptor
::
pipe
(
FileDescriptor
&
read
,
FileDescriptor
&
write
)
{
// Close the descriptors first to make sure that assignments don't throw
// and there are no leaks.
read
_fd
.
close
();
write
_fd
.
close
();
read
.
close
();
write
.
close
();
int
fds
[
2
]
=
{};
if
(
::
pipe
(
fds
)
!=
0
)
fmt
::
ThrowSystemError
(
errno
,
"cannot create pipe"
);
// The following assignments don't throw because read_fd and write_fd
// are closed.
read_fd
=
FileDescriptor
(
fds
[
0
]);
write_fd
=
FileDescriptor
(
fds
[
1
]);
// The following assignments don't throw because read and write are closed.
read
=
FileDescriptor
(
fds
[
0
]);
write
=
FileDescriptor
(
fds
[
1
]);
}
OutputRedirector
::
OutputRedirector
(
FILE
*
file
)
:
file_
(
file
)
{
...
...
test/gtest-extra.h
View file @
8214a5ef
...
...
@@ -202,7 +202,9 @@ class FileDescriptor {
// necessary.
void
dup2
(
int
fd
,
ErrorCode
&
ec
)
FMT_NOEXCEPT
(
true
);
static
void
pipe
(
FileDescriptor
&
read_fd
,
FileDescriptor
&
write_fd
);
// Creates a pipe setting up read and write file descriptors for reading
// and writing respecively. Throws fmt::SystemError on error.
static
void
pipe
(
FileDescriptor
&
read
,
FileDescriptor
&
write
);
};
#if !FMT_USE_RVALUE_REFERENCES
...
...
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