Commit 65d65358 authored by eric@webkit.org's avatar eric@webkit.org

2010-06-04 Kwang Yul Seo <skyul@company100.net>

        Reviewed by Kent Tamura.

        Change filenameFromString to return CString
        https://bugs.webkit.org/show_bug.cgi?id=39494

        filenameFromString returns a newly allocated string and the caller must
        free the string. GTK and EFL ports use g_free while all others ports use
        fastFree. This is confusing because the same function behaves
        differently with respect to ports. Change filenameFromString to return
        CString.

        * platform/FileSystem.cpp:
        (WebCore::filenameFromString):
        * platform/FileSystem.h:
        * platform/efl/FileSystemEfl.cpp:
        (WebCore::filenameFromString):
        * platform/gtk/FileChooserGtk.cpp:
        (WebCore::FileChooser::basenameForWidth):
        * platform/gtk/FileSystemGtk.cpp:
        (WebCore::filenameFromString):
        (WebCore::filenameForDisplay):
        (WebCore::fileExists):
        (WebCore::deleteFile):
        (WebCore::deleteEmptyDirectory):
        (WebCore::getFileSize):
        (WebCore::getFileModificationTime):
        (WebCore::makeAllDirectories):
        (WebCore::pathGetFileName):
        (WebCore::directoryName):
        (WebCore::listDirectory):
        * platform/gtk/SharedBufferGtk.cpp:
        (WebCore::SharedBuffer::createWithContentsOfFile):
        * platform/network/soup/ResourceHandleSoup.cpp:
        (WebCore::startHttp):
        * platform/posix/SharedBufferPOSIX.cpp:
        (WebCore::SharedBuffer::createWithContentsOfFile):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60668 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 461dc1e1
2010-06-04 Kwang Yul Seo <skyul@company100.net>
Reviewed by Kent Tamura.
Change filenameFromString to return CString
https://bugs.webkit.org/show_bug.cgi?id=39494
filenameFromString returns a newly allocated string and the caller must
free the string. GTK and EFL ports use g_free while all others ports use
fastFree. This is confusing because the same function behaves
differently with respect to ports. Change filenameFromString to return
CString.
* platform/FileSystem.cpp:
(WebCore::filenameFromString):
* platform/FileSystem.h:
* platform/efl/FileSystemEfl.cpp:
(WebCore::filenameFromString):
* platform/gtk/FileChooserGtk.cpp:
(WebCore::FileChooser::basenameForWidth):
* platform/gtk/FileSystemGtk.cpp:
(WebCore::filenameFromString):
(WebCore::filenameForDisplay):
(WebCore::fileExists):
(WebCore::deleteFile):
(WebCore::deleteEmptyDirectory):
(WebCore::getFileSize):
(WebCore::getFileModificationTime):
(WebCore::makeAllDirectories):
(WebCore::pathGetFileName):
(WebCore::directoryName):
(WebCore::listDirectory):
* platform/gtk/SharedBufferGtk.cpp:
(WebCore::SharedBuffer::createWithContentsOfFile):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::startHttp):
* platform/posix/SharedBufferPOSIX.cpp:
(WebCore::SharedBuffer::createWithContentsOfFile):
2010-06-04 No'am Rosenthal <noam.rosenthal@nokia.com>
Reviewed by Kenneth Rohde Christiansen.
......
......@@ -31,9 +31,9 @@
namespace WebCore {
#if !PLATFORM(GTK) && !PLATFORM(EFL)
char* filenameFromString(const String& string)
CString filenameFromString(const String& string)
{
return fastStrDup(string.utf8().data());
return string.utf8();
}
#endif
......
......@@ -172,7 +172,7 @@ String roamingUserSpecificStorageDirectory();
bool safeCreateFile(const String&, CFDataRef);
#endif
char* filenameFromString(const String&);
CString filenameFromString(const String&);
#if PLATFORM(GTK)
String filenameToString(const char*);
......
......@@ -56,14 +56,17 @@ CString fileSystemRepresentation(const String& path)
return path.utf8();
}
char* filenameFromString(const String& string)
CString filenameFromString(const String& string)
{
// WARNING: this is just used by platform/network/soup, thus must be GLIB!!!
// TODO: move this to CString and use it instead in both, being more standard
#if PLATFORM(WIN_OS)
return g_strdup(string.utf8().data());
return string.utf8();
#else
return g_uri_unescape_string(string.utf8().data(), 0);
char* filename = g_uri_unescape_string(string.utf8().data(), 0);
CString cfilename(filename);
g_free(filename);
return cfilename;
#endif
}
......
......@@ -57,9 +57,8 @@ String FileChooser::basenameForWidth(const Font& font, int width) const
String string = fileButtonNoFileSelectedLabel();
if (m_filenames.size() == 1) {
gchar* systemFilename = filenameFromString(m_filenames[0]);
gchar* systemBasename = g_path_get_basename(systemFilename);
g_free(systemFilename);
CString systemFilename = filenameFromString(m_filenames[0]);
gchar* systemBasename = g_path_get_basename(systemFilename.data());
stringByAdoptingFileSystemRepresentation(systemBasename, string);
} else if (m_filenames.size() > 1)
return StringTruncator::rightTruncate(multipleFileUploadText(m_filenames.size()), width, font, false);
......
......@@ -52,12 +52,15 @@ String filenameToString(const char* filename)
#endif
}
char* filenameFromString(const String& string)
CString filenameFromString(const String& string)
{
#if OS(WINDOWS)
return g_strdup(string.utf8().data());
return string.utf8();
#else
return g_uri_unescape_string(string.utf8().data(), 0);
char* filename = g_uri_unescape_string(string.utf8().data(), 0);
CString cfilename(filename);
g_free(filename);
return cfilename;
#endif
}
......@@ -67,9 +70,8 @@ String filenameForDisplay(const String& string)
#if OS(WINDOWS)
return string;
#else
gchar* filename = filenameFromString(string);
gchar* display = g_filename_to_utf8(filename, 0, 0, 0, 0);
g_free(filename);
CString filename = filenameFromString(string);
gchar* display = g_filename_to_utf8(filename.data(), 0, 0, 0, 0);
if (!display)
return string;
......@@ -83,12 +85,10 @@ String filenameForDisplay(const String& string)
bool fileExists(const String& path)
{
bool result = false;
gchar* filename = filenameFromString(path);
CString filename = filenameFromString(path);
if (filename) {
result = g_file_test(filename, G_FILE_TEST_EXISTS);
g_free(filename);
}
if (!filename.isNull())
result = g_file_test(filename.data(), G_FILE_TEST_EXISTS);
return result;
}
......@@ -96,12 +96,10 @@ bool fileExists(const String& path)
bool deleteFile(const String& path)
{
bool result = false;
gchar* filename = filenameFromString(path);
CString filename = filenameFromString(path);
if (filename) {
result = g_remove(filename) == 0;
g_free(filename);
}
if (!filename.isNull())
result = g_remove(filename.data()) == 0;
return result;
}
......@@ -109,25 +107,22 @@ bool deleteFile(const String& path)
bool deleteEmptyDirectory(const String& path)
{
bool result = false;
gchar* filename = filenameFromString(path);
CString filename = filenameFromString(path);
if (filename) {
result = g_rmdir(filename) == 0;
g_free(filename);
}
if (!filename.isNull())
result = g_rmdir(filename.data()) == 0;
return result;
}
bool getFileSize(const String& path, long long& resultSize)
{
gchar* filename = filenameFromString(path);
if (!filename)
CString filename = filenameFromString(path);
if (filename.isNull())
return false;
struct stat statResult;
gint result = g_stat(filename, &statResult);
g_free(filename);
gint result = g_stat(filename.data(), &statResult);
if (result != 0)
return false;
......@@ -137,13 +132,12 @@ bool getFileSize(const String& path, long long& resultSize)
bool getFileModificationTime(const String& path, time_t& modifiedTime)
{
gchar* filename = filenameFromString(path);
if (!filename)
CString filename = filenameFromString(path);
if (filename.isNull())
return false;
struct stat statResult;
gint result = g_stat(filename, &statResult);
g_free(filename);
gint result = g_stat(filename.data(), &statResult);
if (result != 0)
return false;
......@@ -162,12 +156,11 @@ String pathByAppendingComponent(const String& path, const String& component)
bool makeAllDirectories(const String& path)
{
gchar* filename = filenameFromString(path);
if (!filename)
CString filename = filenameFromString(path);
if (filename.isNull())
return false;
gint result = g_mkdir_with_parents(filename, S_IRWXU);
g_free(filename);
gint result = g_mkdir_with_parents(filename.data(), S_IRWXU);
return result == 0;
}
......@@ -182,11 +175,10 @@ String pathGetFileName(const String& pathName)
if (pathName.isEmpty())
return pathName;
char* tmpFilename = filenameFromString(pathName);
char* baseName = g_path_get_basename(tmpFilename);
CString tmpFilename = filenameFromString(pathName);
char* baseName = g_path_get_basename(tmpFilename.data());
String fileName = String::fromUTF8(baseName);
g_free(baseName);
g_free(tmpFilename);
return fileName;
}
......@@ -194,7 +186,7 @@ String pathGetFileName(const String& pathName)
String directoryName(const String& path)
{
/* No null checking needed */
GOwnPtr<char> tmpFilename(filenameFromString(path));
GOwnPtr<char> tmpFilename(const_cast<char*>(filenameFromString(path).data()));
GOwnPtr<char> dirname(g_path_get_dirname(tmpFilename.get()));
return String::fromUTF8(dirname.get());
}
......@@ -203,8 +195,8 @@ Vector<String> listDirectory(const String& path, const String& filter)
{
Vector<String> entries;
gchar* filename = filenameFromString(path);
GDir* dir = g_dir_open(filename, 0, 0);
CString filename = filenameFromString(path);
GDir* dir = g_dir_open(filename.data(), 0, 0);
if (!dir)
return entries;
......@@ -213,12 +205,11 @@ Vector<String> listDirectory(const String& path, const String& filter)
if (!g_pattern_match_string(pspec, name))
continue;
gchar* entry = g_build_filename(filename, name, NULL);
gchar* entry = g_build_filename(filename.data(), name, NULL);
entries.append(filenameToString(entry));
g_free(entry);
}
g_dir_close(dir);
g_free(filename);
return entries;
}
......
......@@ -32,19 +32,17 @@ PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& fi
if (filePath.isEmpty())
return 0;
gchar* filename = filenameFromString(filePath);
CString filename = filenameFromString(filePath);
gchar* contents;
gsize size;
GError* error = 0;
if (!g_file_get_contents(filename, &contents, &size, &error)) {
if (!g_file_get_contents(filename.data(), &contents, &size, &error)) {
LOG_ERROR("Failed to fully read contents of file %s - %s", filenameForDisplay(filePath).utf8().data(), error->message);
g_error_free(error);
g_free(filename);
return 0;
}
RefPtr<SharedBuffer> result = SharedBuffer::create(contents, size);
g_free(filename);
g_free(contents);
return result.release();
......
......@@ -533,10 +533,8 @@ static bool startHttp(ResourceHandle* handle)
* libsoup's simple-httpd test
*/
GError* error = 0;
gchar* fileName = filenameFromString(element.m_filename);
GMappedFile* fileMapping = g_mapped_file_new(fileName, false, &error);
g_free(fileName);
CString fileName = filenameFromString(element.m_filename);
GMappedFile* fileMapping = g_mapped_file_new(fileName.data(), false, &error);
if (error) {
g_error_free(error);
......
......@@ -40,9 +40,8 @@ PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& fi
if (filePath.isEmpty())
return 0;
char* filename = filenameFromString(filePath);
int fd = open(filename, O_RDONLY);
fastFree(filename);
CString filename = filenameFromString(filePath);
int fd = open(filename.data(), O_RDONLY);
if (fd == -1)
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment