aboutsummaryrefslogtreecommitdiff
path: root/libbutl/fdstream.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-05-13 00:29:50 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-05-15 15:58:03 +0300
commitc4a9db2f981a03aecf5e9a60e6d27a6dc6dac159 (patch)
treeb40c731b0e1ebdc8abdafddfadc919b64baef8f0 /libbutl/fdstream.cxx
parent041b2137f7351abc8d648ed6a0399feaf331af08 (diff)
Fix VC15 warnings (/W3)
Diffstat (limited to 'libbutl/fdstream.cxx')
-rw-r--r--libbutl/fdstream.cxx26
1 files changed, 16 insertions, 10 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx
index a2d5b09..292324a 100644
--- a/libbutl/fdstream.cxx
+++ b/libbutl/fdstream.cxx
@@ -271,6 +271,14 @@ namespace butl
return save () ? 0 : -1;
}
+#ifdef _WIN32
+ static inline int
+ write (int fd, const void* buf, size_t n)
+ {
+ return _write (fd, buf, static_cast<unsigned int> (n));
+ }
+#endif
+
bool fdbuf::
save ()
{
@@ -282,11 +290,7 @@ namespace butl
// descriptor opened for read-only access (while -1 with errno EBADF is
// expected). This is in contrast with VC's _write() and POSIX's write().
//
-#ifndef _WIN32
- ssize_t m (write (fd_.get (), buf_, n));
-#else
- int m (_write (fd_.get (), buf_, n));
-#endif
+ auto m (write (fd_.get (), buf_, n));
if (m == -1)
throw_ios_failure (errno);
@@ -317,13 +321,15 @@ namespace butl
//
size_t n (static_cast<size_t> (sn));
+ auto advance = [this] (size_t n) {pbump (static_cast<int> (n));};
+
// Buffer the data if there is enough space.
//
size_t an (epptr () - pptr ()); // Amount of free space in the buffer.
if (n <= an)
{
memcpy (pptr (), s, n);
- pbump (n);
+ advance (n);
return n;
}
@@ -377,13 +383,13 @@ namespace butl
else
{
memcpy (pptr (), s, an);
- pbump (an);
+ advance (an);
}
// Flush the buffer.
//
size_t wn (bn + an);
- int r (wn > 0 ? _write (fd_.get (), buf_, wn) : 0);
+ int r (wn > 0 ? write (fd_.get (), buf_, wn) : 0);
if (r == -1)
throw_ios_failure (errno);
@@ -413,13 +419,13 @@ namespace butl
if (n <= static_cast<size_t> (epptr () - pbase ()))
{
memcpy (pbase (), s, n);
- pbump (n);
+ advance (n);
return sn;
}
// The data tail doesn't fit the buffer so write it to the file.
//
- r = _write (fd_.get (), s, n);
+ r = write (fd_.get (), s, n);
if (r == -1)
throw_ios_failure (errno);