From 99709d889f14ef86b38014a50d4d2580909316f1 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 12 Oct 2021 12:12:14 -0400 Subject: [PATCH] fd: start deprecating vector for p{read,write}_or_die Add support for pread and pwrite of ByteVector objects alongside vector. A later commit will delete the template specializations for vector, but existing users have to be updated to use ByteVector first. Nothing currently uses vector, so we can delete that immediately. Signed-off-by: Zygo Blaxell --- include/crucible/fd.h | 10 +++++++--- lib/fd.cc | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/crucible/fd.h b/include/crucible/fd.h index ff390aa..89eec2e 100644 --- a/include/crucible/fd.h +++ b/include/crucible/fd.h @@ -1,6 +1,7 @@ #ifndef CRUCIBLE_FD_H #define CRUCIBLE_FD_H +#include "crucible/bytevector.h" #include "crucible/namedptr.h" #include @@ -125,11 +126,14 @@ namespace crucible { // Specialization for strings which reads/writes the string content, not the struct string template<> void write_or_die(int fd, const string& str); template<> void pread_or_die(int fd, string& str, off_t offset); - template<> void pread_or_die>(int fd, vector& str, off_t offset); - template<> void pread_or_die>(int fd, vector& str, off_t offset); template<> void pwrite_or_die(int fd, const string& str, off_t offset); - template<> void pwrite_or_die>(int fd, const vector& str, off_t offset); + template<> void pread_or_die(int fd, ByteVector& str, off_t offset); + template<> void pwrite_or_die(int fd, const ByteVector& str, off_t offset); + // Deprecated + template<> void pread_or_die>(int fd, vector& str, off_t offset); template<> void pwrite_or_die>(int fd, const vector& str, off_t offset); + template<> void pread_or_die>(int fd, vector& str, off_t offset) = delete; + template<> void pwrite_or_die>(int fd, const vector& str, off_t offset) = delete; // A different approach to reading a simple string string read_string(int fd, size_t size); diff --git a/lib/fd.cc b/lib/fd.cc index cbedda2..bc32485 100644 --- a/lib/fd.cc +++ b/lib/fd.cc @@ -458,7 +458,7 @@ namespace crucible { template<> void - pread_or_die>(int fd, vector &text, off_t offset) + pread_or_die(int fd, ByteVector &text, off_t offset) { return pread_or_die(fd, text.data(), text.size(), offset); } @@ -479,7 +479,7 @@ namespace crucible { template<> void - pwrite_or_die>(int fd, const vector &text, off_t offset) + pwrite_or_die(int fd, const ByteVector &text, off_t offset) { return pwrite_or_die(fd, text.data(), text.size(), offset); }