From 1f211640852a0958495efd574b506f3162e6ef7c Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 9 Mar 2023 19:44:12 -0800 Subject: [PATCH] gcc: remove redundant struct Signed-off-by: Rosen Penev --- app/actions.cpp | 26 +++++++++++++------------- app/exiv2.cpp | 2 +- include/exiv2/types.hpp | 2 +- src/crwimage_int.cpp | 4 ++-- src/http.cpp | 4 ++-- src/jpgimage.cpp | 3 +-- src/nikonmn_int.cpp | 2 +- src/types.cpp | 2 +- unitTests/test_types.cpp | 4 ++-- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index 63302fc6..835ea83f 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -64,7 +64,7 @@ class Timestamp { //! C'tor int read(const std::string& path); //! Read the timestamp from a broken-down time in buffer \em tm. - int read(struct tm* tm); + int read(tm* tm); //! Set the timestamp of a file int touch(const std::string& path) const; @@ -74,16 +74,16 @@ class Timestamp { }; /*! - @brief Convert a string "YYYY:MM:DD HH:MI:SS" to a struct tm type, + @brief Convert a string "YYYY:MM:DD HH:MI:SS" to a tm type, returns 0 if successful */ -int str2Tm(const std::string& timeStr, struct tm* tm); +int str2Tm(const std::string& timeStr, tm* tm); //! Convert a localtime to a string "YYYY:MM:DD HH:MI:SS", "" on error std::string time2Str(time_t time); //! Convert a tm structure to a string "YYYY:MM:DD HH:MI:SS", "" on error -std::string tm2Str(const struct tm* tm); +std::string tm2Str(const tm* tm); /*! @brief Copy metadata from source to target according to Params::copyXyz @@ -107,7 +107,7 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType the file to. @return 0 if successful, -1 if the file was skipped, 1 on error. */ -int renameFile(std::string& path, const struct tm* tm); +int renameFile(std::string& path, const tm* tm); /*! @brief Make a file path from the current file path, destination @@ -637,7 +637,7 @@ int Rename::run(const std::string& path) { std::cerr << _("Image file creation timestamp not set in the file") << " " << path << "\n"; return 1; } - struct tm tm; + tm tm; if (str2Tm(v, &tm) != 0) { std::cerr << _("Failed to parse timestamp") << " `" << v << "' " << _("in the file") << " " << path << "\n"; return 1; @@ -1401,7 +1401,7 @@ int Adjust::adjustDateTime(Exiv2::ExifData& exifData, const std::string& key, co std::cout << " " << adjustment_ << _("s"); } } - struct tm tm; + tm tm; if (str2Tm(timeStr, &tm) != 0) { if (Params::instance().verbose_) std::cout << std::endl; @@ -1584,7 +1584,7 @@ int Timestamp::read(const std::string& path) { return rc; } -int Timestamp::read(struct tm* tm) { +int Timestamp::read(tm* tm) { int rc = 1; time_t t = mktime(tm); // interpret tm according to current timezone settings if (t != static_cast(-1)) { @@ -1598,14 +1598,14 @@ int Timestamp::read(struct tm* tm) { int Timestamp::touch(const std::string& path) const { if (0 == actime_) return 1; - struct utimbuf buf; + utimbuf buf; buf.actime = actime_; buf.modtime = modtime_; return utime(path.c_str(), &buf); } //! @endcond -int str2Tm(const std::string& timeStr, struct tm* tm) { +int str2Tm(const std::string& timeStr, tm* tm) { if (timeStr.empty() || timeStr.front() == ' ') return 1; if (timeStr.length() < 19) @@ -1615,7 +1615,7 @@ int str2Tm(const std::string& timeStr, struct tm* tm) { return 3; if (!tm) return 4; - std::memset(tm, 0x0, sizeof(struct tm)); + std::memset(tm, 0x0, sizeof(*tm)); tm->tm_isdst = -1; int64_t tmp = 0; @@ -1656,7 +1656,7 @@ std::string time2Str(time_t time) { return tm2Str(tm); } // time2Str -std::string tm2Str(const struct tm* tm) { +std::string tm2Str(const tm* tm) { if (!tm) return ""; @@ -1831,7 +1831,7 @@ void replace(std::string& text, const std::string& searchText, const std::string } } -int renameFile(std::string& newPath, const struct tm* tm) { +int renameFile(std::string& newPath, const tm* tm) { auto p = fs::path(newPath); std::string path = newPath; auto oldFsPath = fs::path(path); diff --git a/app/exiv2.cpp b/app/exiv2.cpp index c0855038..8f495047 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -963,7 +963,7 @@ void Params::getStdin(Exiv2::DataBuf& buf) { fd_set readfds; FD_ZERO(&readfds); FD_SET(STDIN_FILENO, &readfds); - struct timeval timeout = {1, 0}; // yes: set timeout seconds,microseconds + timeval timeout = {1, 0}; // yes: set timeout seconds,microseconds // if we have something in the pipe, read it if (select(1, &readfds, nullptr, nullptr, &timeout)) { diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp index b71c9152..38a6e1e0 100644 --- a/include/exiv2/types.hpp +++ b/include/exiv2/types.hpp @@ -332,7 +332,7 @@ EXIV2API bool isHex(const std::string& str, size_t size = 0, const std::string& "2007:05:24 12:31:55" to broken down time format, returns 0 if successful, else 1. */ -EXIV2API int exifTime(const char* buf, struct tm* tm); +EXIV2API int exifTime(const char* buf, tm* tm); /*! @brief Translate a string using the gettext framework. This wrapper hides diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 87cf7779..8917df46 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -741,7 +741,7 @@ void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping* ULongValue v; v.read(ciffComponent.pData(), 8, byteOrder); time_t t = v.value_.at(0); - struct tm r; + tm r; #ifdef _WIN32 auto tm = localtime_s(&r, &t) ? nullptr : &r; #else @@ -930,7 +930,7 @@ void CrwMap::encode0x180e(const Image& image, const CrwMapping* pCrwMapping, Cif time_t t = 0; const ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); if (auto ed = image.exifData().findKey(key); ed != image.exifData().end()) { - struct tm tm = {}; + tm tm = {}; if (exifTime(ed->toString().c_str(), &tm) == 0) { t = ::mktime(&tm); } diff --git a/src/http.cpp b/src/http.cpp index 4a558c31..7197a30b 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -204,7 +204,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st int server = -1; // fill in the address - struct sockaddr_in serv_addr = {}; + sockaddr_in serv_addr = {}; int serv_len = sizeof(serv_addr); serv_addr.sin_addr.s_addr = inet_addr(servername_p); @@ -226,7 +226,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st //////////////////////////////////// // and connect - server = connect(sockfd, reinterpret_cast(&serv_addr), serv_len); + server = connect(sockfd, reinterpret_cast(&serv_addr), serv_len); if (server == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) { closesocket(sockfd); return error(errors, "error - unable to connect to server = %s port = %s wsa_error = %d", servername_p, port_p, diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 10d57aa2..f30610ee 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -866,8 +866,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { if (outIo.write(tmpBuf.data(), 4) != 4) throw Error(ErrorCode::kerImageWriteFailed); - if (outIo.write(reinterpret_cast(const_cast(comment_.data())), comment_.length()) != - comment_.length()) + if (outIo.write(reinterpret_cast(comment_.data()), comment_.length()) != comment_.length()) throw Error(ErrorCode::kerImageWriteFailed); if (outIo.putb(0) == EOF) throw Error(ErrorCode::kerImageWriteFailed); diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index e945b8bd..05505a5a 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -3104,7 +3104,7 @@ std::ostream& Nikon3MakerNote::printLensId(std::ostream& os, const Value& value, * * www.rottmerhusen.com/objektives/lensid/files/c-header/fmountlens4.h */ - const struct FMntLens* pf = fmountlens; + const FMntLens* pf = fmountlens; while (pf->lid && pf->lensname) { if (pf->lid == vid) { break; diff --git a/src/types.cpp b/src/types.cpp index 7e3899a3..aa15cd87 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -488,7 +488,7 @@ bool isHex(const std::string& str, size_t size, const std::string& prefix) { return true; } // isHex -int exifTime(const char* buf, struct tm* tm) { +int exifTime(const char* buf, tm* tm) { int rc = 1; int year = 0, mon = 0, mday = 0, hour = 0, min = 0, sec = 0; if (std::sscanf(buf, "%4d:%2d:%2d %2d:%2d:%2d", &year, &mon, &mday, &hour, &min, &sec) == 6) { diff --git a/unitTests/test_types.cpp b/unitTests/test_types.cpp index f9d3650c..5cfd80d5 100644 --- a/unitTests/test_types.cpp +++ b/unitTests/test_types.cpp @@ -14,7 +14,7 @@ using namespace Exiv2; // More info about tm : http://www.cplusplus.com/reference/ctime/tm/ TEST(ExivTime, getsTimeFromValidString) { - struct tm tmInstance; + tm tmInstance; ASSERT_EQ(0, exifTime("2007:05:24 12:31:55", &tmInstance)); ASSERT_EQ(107, tmInstance.tm_year); // Years since 1900 ASSERT_EQ(4, tmInstance.tm_mon); @@ -25,7 +25,7 @@ TEST(ExivTime, getsTimeFromValidString) { } TEST(ExivTime, doesNotGetTimeWithBadFormedString) { - struct tm tmInstance; + tm tmInstance; ASSERT_EQ(1, exifTime("007:a5:24 aa:bb:cc", &tmInstance)); }