OSDN Git Service

refactoring.
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Tue, 22 Jun 2004 16:21:43 +0000 (16:21 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Tue, 22 Jun 2004 16:21:43 +0000 (16:21 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1191 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/libkita/access.cpp

index 059640b..1f2b2b6 100644 (file)
 
 using namespace Kita;
 
-// copied from http.cc
 // ¥­¥ã¥Ã¥·¥å¤¬¤¢¤ë¤È¤­¤Ï¤½¤ÎÆâÍƤòmalloc¤·¤¿Îΰè¤Ë¥³¥Ô¡¼¤·¤ÆÊÖ¤¹¡£
 // ¥­¥ã¥Ã¥·¥å¤¬¤Ê¤¤¤È¤­¤Ï0¤òÊÖ¤¹¡£
 QCString Access::getCacheData( const KURL& url )
 {
     QString cachePath = Kita::Cache::getPath( url );
 
-    FILE *fs = fopen( QFile::encodeName( cachePath ), "r" );
-    if ( !fs ) {
+    QFile file( cachePath );
+    if ( !file.open( IO_ReadOnly ) ) {
         return 0;
     }
+    int dataSize = file.size();
 
-    struct stat buf;
-    ::stat( QFile::encodeName( cachePath ), &buf );
-    int pos = ftell( fs );
-    int datasize = buf.st_size - pos;
-
-    char* ret = static_cast<char *>( malloc( datasize + 1 ) );
-    fread( ret, datasize, 1, fs );
-    ret[ datasize ] = '\0';
-    fclose( fs );
+    char* ret = static_cast<char *>( malloc( dataSize + 1 ) );
+    file.readBlock( ret, dataSize );
+    ret[ dataSize ] = '\0';
     return ret;
 }