Fix MSVC build.
This commit is contained in:
parent
1a2d7be3f5
commit
8214a5ef5e
@ -42,9 +42,6 @@
|
|||||||
# define O_TRUNC _O_TRUNC
|
# define O_TRUNC _O_TRUNC
|
||||||
# define S_IRUSR _S_IREAD
|
# define S_IRUSR _S_IREAD
|
||||||
# define S_IWUSR _S_IWRITE
|
# define S_IWUSR _S_IWRITE
|
||||||
# define close _close
|
|
||||||
# define dup _dup
|
|
||||||
# define dup2 _dup2
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
// Retries the expression while it evaluates to -1 and error equals to EINTR.
|
// 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;
|
int mode = S_IRUSR | S_IWUSR;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fd_ = -1;
|
fd_ = -1;
|
||||||
_sopen_s(&fd, path, oflag, _SH_DENYNO, mode);
|
_sopen_s(&fd_, path, oflag, _SH_DENYNO, mode);
|
||||||
#else
|
#else
|
||||||
FMT_RETRY(fd_, open(path, oflag, mode));
|
FMT_RETRY(fd_, open(path, oflag, mode));
|
||||||
#endif
|
#endif
|
||||||
@ -70,13 +67,13 @@ void FileDescriptor::close() {
|
|||||||
return;
|
return;
|
||||||
// Don't need to retry close in case of EINTR.
|
// Don't need to retry close in case of EINTR.
|
||||||
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
|
// 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");
|
fmt::ReportSystemError(errno, "cannot close file");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor FileDescriptor::dup(int fd) {
|
FileDescriptor FileDescriptor::dup(int fd) {
|
||||||
int new_fd = 0;
|
int new_fd = 0;
|
||||||
FMT_RETRY(new_fd, ::dup(fd));
|
FMT_RETRY(new_fd, ::FMT_POSIX(dup(fd)));
|
||||||
if (new_fd == -1)
|
if (new_fd == -1)
|
||||||
fmt::ThrowSystemError(errno, "cannot duplicate file descriptor {}") << fd;
|
fmt::ThrowSystemError(errno, "cannot duplicate file descriptor {}") << fd;
|
||||||
return FileDescriptor(new_fd);
|
return FileDescriptor(new_fd);
|
||||||
@ -84,7 +81,7 @@ FileDescriptor FileDescriptor::dup(int fd) {
|
|||||||
|
|
||||||
void FileDescriptor::dup2(int fd) {
|
void FileDescriptor::dup2(int fd) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
FMT_RETRY(result, ::dup2(fd_, fd));
|
FMT_RETRY(result, ::FMT_POSIX(dup2(fd_, fd)));
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
fmt::ThrowSystemError(errno,
|
fmt::ThrowSystemError(errno,
|
||||||
"cannot duplicate file descriptor {} to {}") << fd_ << fd;
|
"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) {
|
void FileDescriptor::dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT(true) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
FMT_RETRY(result, ::dup2(fd_, fd));
|
FMT_RETRY(result, ::FMT_POSIX(dup2(fd_, fd)));
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
ec = ErrorCode(errno);
|
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
|
// Close the descriptors first to make sure that assignments don't throw
|
||||||
// and there are no leaks.
|
// and there are no leaks.
|
||||||
read_fd.close();
|
read.close();
|
||||||
write_fd.close();
|
write.close();
|
||||||
int fds[2] = {};
|
int fds[2] = {};
|
||||||
if (::pipe(fds) != 0)
|
if (::pipe(fds) != 0)
|
||||||
fmt::ThrowSystemError(errno, "cannot create pipe");
|
fmt::ThrowSystemError(errno, "cannot create pipe");
|
||||||
// The following assignments don't throw because read_fd and write_fd
|
// The following assignments don't throw because read and write are closed.
|
||||||
// are closed.
|
read = FileDescriptor(fds[0]);
|
||||||
read_fd = FileDescriptor(fds[0]);
|
write = FileDescriptor(fds[1]);
|
||||||
write_fd = FileDescriptor(fds[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputRedirector::OutputRedirector(FILE *file) : file_(file) {
|
OutputRedirector::OutputRedirector(FILE *file) : file_(file) {
|
||||||
|
@ -202,7 +202,9 @@ class FileDescriptor {
|
|||||||
// necessary.
|
// necessary.
|
||||||
void dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT(true);
|
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
|
#if !FMT_USE_RVALUE_REFERENCES
|
||||||
|
Loading…
Reference in New Issue
Block a user