From d87c91a396179516c8ba900dc402dfcb7063af83 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 3 Dec 2005 06:44:02 +0000 Subject: [PATCH] Make mapping of empty files work. (#321530) 2005-12-03 Matthias Clasen * glib/gmappedfile.c: Make mapping of empty files work. (#321530) --- ChangeLog | 3 +++ ChangeLog.pre-2-10 | 3 +++ ChangeLog.pre-2-12 | 3 +++ glib/gmappedfile.c | 17 ++++++++++++++--- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30e4ff7..8cc4eef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2005-12-03 Matthias Clasen + * glib/gmappedfile.c: Make mapping of empty files + work. (#321530) + * glib/gfileutils.c: Don't fork a new process just to fix the permissions of the created temp file. (#321318, Alexis S. L. Carvalho) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 30e4ff7..8cc4eef 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,8 @@ 2005-12-03 Matthias Clasen + * glib/gmappedfile.c: Make mapping of empty files + work. (#321530) + * glib/gfileutils.c: Don't fork a new process just to fix the permissions of the created temp file. (#321318, Alexis S. L. Carvalho) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 30e4ff7..8cc4eef 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,8 @@ 2005-12-03 Matthias Clasen + * glib/gmappedfile.c: Make mapping of empty files + work. (#321530) + * glib/gfileutils.c: Don't fork a new process just to fix the permissions of the created temp file. (#321318, Alexis S. L. Carvalho) diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c index 9935356..d3d4de8 100644 --- a/glib/gmappedfile.c +++ b/glib/gmappedfile.c @@ -137,6 +137,14 @@ g_mapped_file_new (const gchar *filename, goto out; } + if (st.st_size == 0) + { + file->length = 0; + file->contents = ""; + close (fd); + return file; + } + file->contents = MAP_FAILED; #ifdef HAVE_MMAP @@ -251,13 +259,16 @@ g_mapped_file_free (GMappedFile *file) { g_return_if_fail (file != NULL); + if (file->length) + { #ifdef HAVE_MMAP - munmap (file->contents, file->length); + munmap (file->contents, file->length); #endif #ifdef G_OS_WIN32 - UnmapViewOfFile (file->contents); - CloseHandle (file->mapping); + UnmapViewOfFile (file->contents); + CloseHandle (file->mapping); #endif + } g_free (file); } -- 2.7.4