std::rewind cannot handle error indicators.
Change-Id: I8c4006c5378a19c6e761708df619f1d77261d8bd
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
X509Ptr x509(::PEM_read_X509(fp.get(), NULL, NULL, NULL),
::X509_free);
if (x509 == nullptr) {
X509Ptr x509(::PEM_read_X509(fp.get(), NULL, NULL, NULL),
::X509_free);
if (x509 == nullptr) {
+ std::fseek(fp.get(), 0L, SEEK_SET);
+ if (std::ferror(fp.get()))
+ throw std::logic_error("Failed to set the position as beginning.");
+
x509 = X509Ptr(::PEM_read_X509_AUX(fp.get(), NULL, NULL, NULL),
::X509_free);
}
x509 = X509Ptr(::PEM_read_X509_AUX(fp.get(), NULL, NULL, NULL),
::X509_free);
}
throw std::invalid_argument("Failed to open [" + path + "].");
std::fseek(fp.get(), 0L, SEEK_END);
throw std::invalid_argument("Failed to open [" + path + "].");
std::fseek(fp.get(), 0L, SEEK_END);
+ if (std::ferror(fp.get()))
+ throw std::logic_error("Failed to set the position as end [" + path + "].");
+
unsigned int fsize = std::ftell(fp.get());
unsigned int fsize = std::ftell(fp.get());
+ std::fseek(fp.get(), 0L, SEEK_SET);
+ if (std::ferror(fp.get()))
+ throw std::logic_error("Failed to set the position as beginning [" + path + "].");
std::string buff(fsize, 0);
if (fsize != std::fread(static_cast<void*>(&buff[0]), 1, fsize, fp.get()))
throw std::logic_error("Failed to read [" + path + "]");
std::string buff(fsize, 0);
if (fsize != std::fread(static_cast<void*>(&buff[0]), 1, fsize, fp.get()))
throw std::logic_error("Failed to read [" + path + "]");