SharedBufferGtk.cpp [plain text]
#include "config.h"
#include "SharedBuffer.h"
#include "FileSystem.h"
#include <wtf/gobject/GUniquePtr.h>
#include <wtf/text/CString.h>
#include <glib.h>
namespace WebCore {
PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
{
if (filePath.isEmpty())
return 0;
CString filename = fileSystemRepresentation(filePath);
GUniqueOutPtr<gchar> contents;
gsize size;
GUniqueOutPtr<GError> error;
if (!g_file_get_contents(filename.data(), &contents.outPtr(), &size, &error.outPtr())) {
LOG_ERROR("Failed to fully read contents of file %s - %s", filenameForDisplay(filePath).utf8().data(), error->message);
return 0;
}
RefPtr<SharedBuffer> result = SharedBuffer::create(contents.get(), size);
return result.release();
}
}