[glib] Return NULL from g_mapped_file_get_contents()
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib] Return NULL from g_mapped_file_get_contents()
- Date: Thu, 28 Jan 2010 02:33:44 +0000 (UTC)
commit b0a0ac51cb7e628f90b8293c098a6a1a26425301
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Jan 27 21:30:26 2010 -0500
Return NULL from g_mapped_file_get_contents()
In the case of an empty file, return NULL instead of "". This means
that the return result of g_mapped_file_get_contents() will always be
page-aligned.
README.in | 5 +++++
glib/gmappedfile.c | 6 ++++--
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/README.in b/README.in
index 52707f7..94a3c2a 100644
--- a/README.in
+++ b/README.in
@@ -39,6 +39,11 @@ Notes about GLib 2.24
while an object is being initialized. If this behavior is needed, setting a
custom constructor that just chains up will re-enable this functionality.
+* GMappedFile on an empty file now returns NULL for the contents instead of
+ returning an empty string. The documentation specifically states that code
+ may not rely on nul-termination here so any breakage caused by this change
+ is a bug in application code.
+
Notes about GLib 2.22
=====================
diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c
index 77865b8..347f964 100644
--- a/glib/gmappedfile.c
+++ b/glib/gmappedfile.c
@@ -148,7 +148,7 @@ g_mapped_file_new (const gchar *filename,
if (st.st_size == 0)
{
file->length = 0;
- file->contents = "";
+ file->contents = NULL;
close (fd);
return file;
}
@@ -242,7 +242,9 @@ g_mapped_file_get_length (GMappedFile *file)
* Note that the contents may not be zero-terminated,
* even if the #GMappedFile is backed by a text file.
*
- * Returns: the contents of @file.
+ * If the file is empty then %NULL is returned.
+ *
+ * Returns: the contents of @file, or %NULL.
*
* Since: 2.8
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]