From 42e678071fdbda4890b24c9138c426c573e3ea56 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 10 May 2023 13:06:26 +0200 Subject: Add fdwrite() --- libbutl/fdstream.cxx | 26 +++++++++++++++----------- libbutl/fdstream.hxx | 5 +++++ 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'libbutl') 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 (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 (n)); + } + #endif pair 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 -- cgit v1.1