mirror of https://github.com/aria2/aria2
2009-09-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed unused methods Util::fileCopy(), Util::rangedFileCopy(), Util::expandBuffer(), Util::unfoldRange(), Util::indexRange() and Util::httpGMT(). * src/Util.cc * src/Util.h * test/UtilTest.ccpull/1/head
parent
414862fabc
commit
909b126180
|
@ -1,3 +1,12 @@
|
|||
2009-09-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Removed unused methods Util::fileCopy(), Util::rangedFileCopy(),
|
||||
Util::expandBuffer(), Util::unfoldRange(), Util::indexRange() and
|
||||
Util::httpGMT().
|
||||
* src/Util.cc
|
||||
* src/Util.h
|
||||
* test/UtilTest.cc
|
||||
|
||||
2009-09-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
* Release 1.6.0
|
||||
|
|
114
src/Util.cc
114
src/Util.cc
|
@ -295,46 +295,6 @@ FILE* Util::openFile(const std::string& filename, const std::string& mode) {
|
|||
return file;
|
||||
}
|
||||
|
||||
void Util::fileCopy(const std::string& dest, const std::string& src) {
|
||||
File file(src);
|
||||
rangedFileCopy(dest, src, 0, file.size());
|
||||
}
|
||||
|
||||
void Util::rangedFileCopy(const std::string& dest, const std::string& src, off_t srcOffset, uint64_t length)
|
||||
{
|
||||
size_t bufSize = 4096;
|
||||
unsigned char buf[bufSize];
|
||||
DefaultDiskWriter srcdw(src);
|
||||
DefaultDiskWriter destdw(dest);
|
||||
|
||||
srcdw.openExistingFile();
|
||||
destdw.initAndOpenFile();
|
||||
|
||||
lldiv_t res = lldiv(length, bufSize);
|
||||
unsigned int x = res.quot;
|
||||
unsigned int r = res.rem;
|
||||
|
||||
off_t initialOffset = srcOffset;
|
||||
for(unsigned int i = 0; i < x; ++i) {
|
||||
size_t readLength = 0;
|
||||
while(readLength < bufSize) {
|
||||
ssize_t ret = srcdw.readData(buf, bufSize-readLength, srcOffset);
|
||||
destdw.writeData(buf, ret, srcOffset-initialOffset);
|
||||
srcOffset += ret;
|
||||
readLength += ret;
|
||||
}
|
||||
}
|
||||
if(r > 0) {
|
||||
size_t readLength = 0;
|
||||
while(readLength < r) {
|
||||
ssize_t ret = srcdw.readData(buf, r-readLength, srcOffset);
|
||||
destdw.writeData(buf, ret, srcOffset-initialOffset);
|
||||
srcOffset += ret;
|
||||
readLength += ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Util::isPowerOf(int num, int base) {
|
||||
if(base <= 0) { return false; }
|
||||
if(base == 1) { return true; }
|
||||
|
@ -372,14 +332,6 @@ std::string Util::secfmt(time_t sec) {
|
|||
return str;
|
||||
}
|
||||
|
||||
size_t Util::expandBuffer(char** pbuf, size_t curLength, size_t newLength) {
|
||||
char* newbuf = new char[newLength];
|
||||
memcpy(newbuf, *pbuf, curLength);
|
||||
delete [] *pbuf;
|
||||
*pbuf = newbuf;
|
||||
return newLength;
|
||||
}
|
||||
|
||||
int getNum(const char* buf, int offset, size_t length) {
|
||||
char* temp = new char[length+1];
|
||||
memcpy(temp, buf+offset, length);
|
||||
|
@ -389,44 +341,6 @@ int getNum(const char* buf, int offset, size_t length) {
|
|||
return x;
|
||||
}
|
||||
|
||||
void unfoldSubRange(const std::string& src, std::deque<int>& range) {
|
||||
if(src.empty()) {
|
||||
return;
|
||||
}
|
||||
std::string::size_type p = src.find_first_of(",-");
|
||||
if(p == 0) {
|
||||
return;
|
||||
} else if(p == std::string::npos) {
|
||||
range.push_back(atoi(src.c_str()));
|
||||
} else {
|
||||
if(src.at(p) == ',') {
|
||||
int num = getNum(src.c_str(), 0, p);
|
||||
range.push_back(num);
|
||||
unfoldSubRange(src.substr(p+1), range);
|
||||
} else if(src.at(p) == '-') {
|
||||
std::string::size_type rightNumBegin = p+1;
|
||||
std::string::size_type nextDelim = src.find_first_of(",", rightNumBegin);
|
||||
if(nextDelim == std::string::npos) {
|
||||
nextDelim = src.size();
|
||||
}
|
||||
int left = getNum(src.c_str(), 0, p);
|
||||
int right = getNum(src.c_str(), rightNumBegin, nextDelim-rightNumBegin);
|
||||
for(int i = left; i <= right; ++i) {
|
||||
range.push_back(i);
|
||||
}
|
||||
if(src.size() > nextDelim) {
|
||||
unfoldSubRange(src.substr(nextDelim+1), range);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Util::unfoldRange(const std::string& src, std::deque<int>& range) {
|
||||
unfoldSubRange(src, range);
|
||||
std::sort(range.begin(), range.end());
|
||||
range.erase(std::unique(range.begin(), range.end()), range.end());
|
||||
}
|
||||
|
||||
int32_t Util::parseInt(const std::string& s, int32_t base)
|
||||
{
|
||||
std::string trimed = Util::trim(s);
|
||||
|
@ -621,17 +535,6 @@ void Util::setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
|||
#endif // HAVE_SIGACTION
|
||||
}
|
||||
|
||||
void Util::indexRange(size_t& startIndex, size_t& endIndex,
|
||||
off_t offset, size_t srcLength, size_t destLength)
|
||||
{
|
||||
int64_t _startIndex = offset/destLength;
|
||||
int64_t _endIndex = (offset+srcLength-1)/destLength;
|
||||
assert(_startIndex <= INT32_MAX);
|
||||
assert(_endIndex <= INT32_MAX);
|
||||
startIndex = _startIndex;
|
||||
endIndex = _endIndex;
|
||||
}
|
||||
|
||||
std::string Util::getHomeDir()
|
||||
{
|
||||
const char* p = getenv("HOME");
|
||||
|
@ -691,23 +594,6 @@ std::string Util::abbrevSize(int64_t size)
|
|||
return result;
|
||||
}
|
||||
|
||||
time_t Util::httpGMT(const std::string& httpStdTime)
|
||||
{
|
||||
struct tm tm;
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
char* r = strptime(httpStdTime.c_str(), "%a, %Y-%m-%d %H:%M:%S GMT", &tm);
|
||||
if(r != httpStdTime.c_str()+httpStdTime.size()) {
|
||||
return -1;
|
||||
}
|
||||
time_t thetime = timegm(&tm);
|
||||
if(thetime == -1) {
|
||||
if(tm.tm_year >= 2038-1900) {
|
||||
thetime = INT32_MAX;
|
||||
}
|
||||
}
|
||||
return thetime;
|
||||
}
|
||||
|
||||
void Util::sleep(long seconds) {
|
||||
#ifdef HAVE_SLEEP
|
||||
::sleep(seconds);
|
||||
|
|
22
src/Util.h
22
src/Util.h
|
@ -189,18 +189,10 @@ public:
|
|||
|
||||
static FILE* openFile(const std::string& filename, const std::string& mode);
|
||||
|
||||
static void fileCopy(const std::string& destFile, const std::string& src);
|
||||
|
||||
static void rangedFileCopy(const std::string& destFile, const std::string& src, off_t srcOffset, uint64_t length);
|
||||
|
||||
static bool isPowerOf(int num, int base);
|
||||
|
||||
static std::string secfmt(time_t sec);
|
||||
|
||||
static size_t expandBuffer(char** pbuf, size_t curLength, size_t newLength);
|
||||
|
||||
static void unfoldRange(const std::string& src, std::deque<int>& range);
|
||||
|
||||
static int32_t parseInt(const std::string& s, int32_t base = 10);
|
||||
|
||||
static uint32_t parseUInt(const std::string& s, int base = 10);
|
||||
|
@ -225,26 +217,12 @@ public:
|
|||
|
||||
static void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
|
||||
|
||||
static void indexRange(size_t& startIndex, size_t& endIndex,
|
||||
off_t offset,
|
||||
size_t srcLength, size_t destLength);
|
||||
|
||||
static std::string getHomeDir();
|
||||
|
||||
static int64_t getRealSize(const std::string& sizeWithUnit);
|
||||
|
||||
static std::string abbrevSize(int64_t size);
|
||||
|
||||
/**
|
||||
* Parses given httpTimeFormat and returns seconds ellapsed since epoc.
|
||||
* The available format is "%a, %Y-%m-%d %H:%M:%S GMT".
|
||||
* If specified date is later than "Tue, 2038-01-19 3:14:7 GMT",
|
||||
* this function returns INT32_MAX.
|
||||
* This function also cannot handle prior 1900-1-1 0:0:0 GMT.
|
||||
* If parse operation is failed, then return -1.
|
||||
*/
|
||||
static time_t httpGMT(const std::string& httpTimeFormat);
|
||||
|
||||
template<typename InputIterator>
|
||||
static void toStream
|
||||
(InputIterator first, InputIterator last, std::ostream& os)
|
||||
|
|
|
@ -48,7 +48,6 @@ class UtilTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testToString_binaryStream);
|
||||
CPPUNIT_TEST(testItos);
|
||||
CPPUNIT_TEST(testUitos);
|
||||
CPPUNIT_TEST(testHttpGMT);
|
||||
CPPUNIT_TEST(testNtoh64);
|
||||
CPPUNIT_TEST(testUrlencode);
|
||||
CPPUNIT_TEST(testHtmlEscape);
|
||||
|
@ -92,7 +91,6 @@ public:
|
|||
void testToString_binaryStream();
|
||||
void testItos();
|
||||
void testUitos();
|
||||
void testHttpGMT();
|
||||
void testNtoh64();
|
||||
void testUrlencode();
|
||||
void testHtmlEscape();
|
||||
|
@ -690,22 +688,6 @@ void UtilTest::testUitos()
|
|||
}
|
||||
}
|
||||
|
||||
void UtilTest::testHttpGMT()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)0, Util::httpGMT("Thu, 1970-01-01 0:0:0 GMT"));
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)2147483647,
|
||||
Util::httpGMT("Tue, 2038-01-19 3:14:7 GMT"));
|
||||
if(sizeof(time_t) == 4) {
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)2147483647,
|
||||
Util::httpGMT("Tue, 2038-01-19 3:14:8 GMT"));
|
||||
} else if(sizeof(time_t) == 8) {
|
||||
CPPUNIT_ASSERT_EQUAL((int64_t)2147483648LL,
|
||||
(int64_t)Util::httpGMT("Tue, 2038-01-19 3:14:8 GMT"));
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)-1,
|
||||
Util::httpGMT("Tue, 2008/10/10 23:33:33 UTC"));
|
||||
}
|
||||
|
||||
void UtilTest::testNtoh64()
|
||||
{
|
||||
uint64_t x = 0xff00ff00ee00ee00LL;
|
||||
|
|
Loading…
Reference in New Issue