aboutsummaryrefslogtreecommitdiff
path: root/libbutl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-05-10 13:06:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-05-10 13:06:26 +0200
commit42e678071fdbda4890b24c9138c426c573e3ea56 (patch)
treea7865304d9fb27164ae2fc2bf5e3eb0d597f5dc9 /libbutl
parentb6706518054efa9440c8b5b43412e95ad0e73f89 (diff)
Add fdwrite()
Diffstat (limited to 'libbutl')
-rw-r--r--libbutl/fdstream.cxx26
-rw-r--r--libbutl/fdstream.hxx5
2 files changed, 20 insertions, 11 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx
index 77002ce..5a0c479 100644
--- a/libbutl/fdstream.cxx
+++ b/libbutl/fdstream.cxx
@@ -353,14 +353,6 @@ 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 fdstreambuf::
save ()
{
@@ -372,7 +364,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().
//
- auto m (write (fd_.get (), buf_, n));
+ auto m (fdwrite (fd_.get (), buf_, n));
if (m == -1)
throw_generic_ios_failure (errno);
@@ -487,7 +479,7 @@ namespace butl
// Flush the buffer.
//
size_t wn (bn + an);
- int r (wn > 0 ? write (fd_.get (), buf_, wn) : 0);
+ streamsize r (wn > 0 ? fdwrite (fd_.get (), buf_, wn) : 0);
if (r == -1)
throw_generic_ios_failure (errno);
@@ -530,7 +522,7 @@ namespace butl
// The data tail doesn't fit the buffer so write it to the file.
//
- r = write (fd_.get (), s, n);
+ r = fdwrite (fd_.get (), s, n);
if (r == -1)
throw_generic_ios_failure (errno);
@@ -1579,6 +1571,12 @@ namespace butl
return read (fd, buf, n);
}
+ streamsize
+ fdwrite (int fd, const void* buf, size_t n)
+ {
+ return write (fd, buf, n);
+ }
+
#else
auto_fd
@@ -2124,6 +2122,12 @@ namespace butl
return r;
}
+ streamsize
+ fdwrite (int fd, const void* buf, size_t n)
+ {
+ return _write (fd, buf, static_cast<unsigned int> (n));
+ }
+
#endif
pair<size_t, size_t>
diff --git a/libbutl/fdstream.hxx b/libbutl/fdstream.hxx
index 72634f5..683a2f2 100644
--- a/libbutl/fdstream.hxx
+++ b/libbutl/fdstream.hxx
@@ -975,6 +975,11 @@ namespace butl
//
LIBBUTL_SYMEXPORT std::streamsize
fdread (int, void*, std::size_t);
+
+ // POSIX write() function wrapper, for uniformity.
+ //
+ LIBBUTL_SYMEXPORT std::streamsize
+ fdwrite (int, const void*, std::size_t);
}
#include <libbutl/fdstream.ixx>