X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/45c64b28bad0a8a76f7cbb1413ad6d64fc71eb66..cfa3d7ba83b57ac7a9fa6b79ae73ef9cebcb55f4:/src/common/tarstrm.cpp diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index 513ea00187..65a4099d41 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -19,7 +19,6 @@ #include "wx/tarstrm.h" #ifndef WX_PRECOMP - #include "wx/hashmap.h" #include "wx/intl.h" #include "wx/log.h" #include "wx/utils.h" @@ -62,7 +61,7 @@ enum { }; enum { - TAR_BLOCKSIZE = 512, + TAR_BLOCKSIZE = 512 }; // checksum type @@ -109,10 +108,10 @@ wxTarClassFactory::GetProtocols(wxStreamProtocolType type) const static const wxChar *empty[] = { NULL }; switch (type) { - case wxSTREAM_PROTOCOL: return protocols; - case wxSTREAM_MIMETYPE: return mimetypes; - case wxSTREAM_FILEEXTENSION: return fileexts; - default: return empty; + case wxSTREAM_PROTOCOL: return protocols; + case wxSTREAM_MIMETYPE: return mimetypes; + case wxSTREAM_FILEEXT: return fileexts; + default: return empty; } } @@ -155,7 +154,7 @@ private: static void check(); }; -wxDEFINE_SCOPED_PTR_TYPE(wxTarHeaderBlock); +wxDEFINE_SCOPED_PTR_TYPE(wxTarHeaderBlock) // A table giving the field names and offsets in a tar header block const wxTarField wxTarHeaderBlock::fields[] = @@ -182,10 +181,12 @@ const wxTarField wxTarHeaderBlock::fields[] = void wxTarHeaderBlock::check() { +#if 0 wxCOMPILE_TIME_ASSERT( WXSIZEOF(fields) == TAR_NUMFIELDS + 1, Wrong_number_of_elements_in_fields_table ); +#endif } bool wxTarHeaderBlock::IsAllZeros() const @@ -246,7 +247,7 @@ bool wxTarHeaderBlock::Write(wxOutputStream& out) return ok; } -bool wxTarHeaderBlock::WriteField(wxOutputStream& out, int id) +inline bool wxTarHeaderBlock::WriteField(wxOutputStream& out, int id) { return out.Write(Get(id), Len(id)).LastWrite() == Len(id); } @@ -269,7 +270,7 @@ bool wxTarHeaderBlock::SetOctal(int id, wxTarNumber n) char *p = field + Len(id); *--p = 0; while (p > field) { - *--p = '0' + (n & 7); + *--p = char('0' + (n & 7)); n >>= 3; } return n == 0; @@ -288,7 +289,10 @@ bool wxTarHeaderBlock::SetPath(const wxString& name, wxMBConv& conv) size_t len = name.length(); wxCharBuffer approx(len); for (size_t i = 0; i < len; i++) - approx.data()[i] = name[i] & ~0x7F ? '_' : name[i]; + { + wxChar c = name[i]; + approx.data()[i] = c & ~0x7F ? '_' : c; + } nameBuf = approx; } @@ -380,7 +384,7 @@ static inline wxFileOffset GetDataSize(const wxTarEntry& entry) return 0; default: return entry.GetSize(); - }; + } } @@ -413,7 +417,8 @@ wxTarEntry::~wxTarEntry() } wxTarEntry::wxTarEntry(const wxTarEntry& e) - : m_Name(e.m_Name), + : wxArchiveEntry(), + m_Name(e.m_Name), m_Mode(e.m_Mode), m_IsModeSet(e.m_IsModeSet), m_UserId(e.m_UserId), @@ -528,14 +533,14 @@ wxString wxTarEntry::GetInternalName(const wxString& name, bool wxTarEntry::IsDir() const { - return m_TypeFlag - wxTAR_DIRTYPE == 0; + return m_TypeFlag == wxTAR_DIRTYPE; } void wxTarEntry::SetIsDir(bool isDir) { if (isDir) m_TypeFlag = wxTAR_DIRTYPE; - else if (m_TypeFlag - wxTAR_DIRTYPE == 0) + else if (m_TypeFlag == wxTAR_DIRTYPE) m_TypeFlag = wxTAR_REGTYPE; } @@ -824,8 +829,8 @@ wxTarNumber wxTarInputStream::GetHeaderNumber(int id) const if ((value = GetExtendedHeader(m_hdr->Name(id))) != wxEmptyString) { wxTarNumber n = 0; - const wxChar *p = value; - while (*p == ' ') + wxString::const_iterator p = value.begin(); + while (*p == ' ' && p != value.end()) p++; while (isdigit(*p)) n = n * 10 + (*p++ - '0'); @@ -1047,10 +1052,10 @@ bool wxTarOutputStream::PutNextEntry(wxTarEntry *entry) wxTAR_LNKTYPE, wxTAR_SYMTYPE, wxTAR_CHRTYPE, wxTAR_BLKTYPE, wxTAR_DIRTYPE, wxTAR_FIFOTYPE, 0 }; - char typeflag = e->GetTypeFlag(); + int typeflag = e->GetTypeFlag(); // pax does now allow data for wxTAR_LNKTYPE - if (!m_pax || typeflag - wxTAR_LNKTYPE != 0) + if (!m_pax || typeflag != wxTAR_LNKTYPE) if (strchr(nodata, typeflag) != NULL) CloseEntry(); } @@ -1160,7 +1165,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) if (entry.GetSize() == wxInvalidOffset) entry.SetSize(0); - m_large = SetHeaderNumber(TAR_SIZE, entry.GetSize()); + m_large = !SetHeaderNumber(TAR_SIZE, entry.GetSize()); SetHeaderDate(_T("mtime"), entry.GetDateTime()); if (entry.GetAccessTime().IsValid()) @@ -1168,7 +1173,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) if (entry.GetCreateTime().IsValid()) SetHeaderDate(_T("ctime"), entry.GetCreateTime()); - *m_hdr->Get(TAR_TYPEFLAG) = entry.GetTypeFlag(); + *m_hdr->Get(TAR_TYPEFLAG) = char(entry.GetTypeFlag()); strcpy(m_hdr->Get(TAR_MAGIC), USTAR_MAGIC); strcpy(m_hdr->Get(TAR_VERSION), USTAR_VERSION); @@ -1263,7 +1268,7 @@ wxString wxTarOutputStream::PaxHeaderPath(const wxString& format, if (end == wxString::npos || end + 1 >= format.length()) break; ret << format.substr(begin, end - begin); - switch (format[end + 1]) { + switch ( format[end + 1].GetValue() ) { case 'd': ret << d; break; case 'f': ret << f; break; case 'p': ret << wxGetProcessId(); break; @@ -1338,7 +1343,8 @@ void wxTarOutputStream::SetHeaderDate(const wxString& key, wxLongLong ll = datetime.IsValid() ? datetime.GetValue() : wxLongLong(0); wxLongLong secs = ll / 1000L; - if (key != _T("mtime") || !m_hdr->SetOctal(TAR_MTIME, secs.GetValue()) + if (key != _T("mtime") + || !m_hdr->SetOctal(TAR_MTIME, wxTarNumber(secs.GetValue())) || secs <= 0 || secs >= 0x7fffffff) { wxString str; @@ -1356,11 +1362,16 @@ void wxTarOutputStream::SetExtendedHeader(const wxString& key, const wxString& value) { if (m_pax) { +#if wxUSE_UNICODE + const wxCharBuffer utf_key = key.utf8_str(); + const wxCharBuffer utf_value = value.utf8_str(); +#else const wxWX2WCbuf wide_key = key.wc_str(GetConv()); const wxCharBuffer utf_key = wxConvUTF8.cWC2MB(wide_key); const wxWX2WCbuf wide_value = value.wc_str(GetConv()); const wxCharBuffer utf_value = wxConvUTF8.cWC2MB(wide_value); +#endif // wxUSE_UNICODE/!wxUSE_UNICODE // a small buffer to format the length field in char buf[32];