[glib/glib-2-30: 37/41] GMappedFile: return an error when trying to map a device



commit 500202a8541d9ffc3c00b9921e5526ba0c2d59e2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 17 19:58:28 2011 -0400

    GMappedFile: return an error when trying to map a device
    
    Previously, we were returning an empty buffer for all filenames
    where fstat() gives a size of 0. But this is only appropriate
    for regular files.
    
    Also improve the documentation around this issue. Based on a
    patch by Ryan Lortie.

 docs/reference/glib/tmpl/fileutils.sgml |    4 ++--
 glib/gmappedfile.c                      |   13 +++++++++----
 glib/tests/mappedfile.c                 |    2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/glib/tmpl/fileutils.sgml b/docs/reference/glib/tmpl/fileutils.sgml
index 7b65df6..5590517 100644
--- a/docs/reference/glib/tmpl/fileutils.sgml
+++ b/docs/reference/glib/tmpl/fileutils.sgml
@@ -80,8 +80,8 @@ differences in when a system will report a given error, etc.
      couldn't find the device.  This can mean that the device file was
      installed incorrectly, or that the physical device is missing or
      not correctly attached to the computer.
- G_FILE_ERROR_NODEV: This file is of a type that doesn't support
-     mapping.
+ G_FILE_ERROR_NODEV: The  underlying  file system of the specified file
+     does not support memory mapping.
 @G_FILE_ERROR_ROFS: The directory containing the new link can't be
           modified because it's on a read-only file system.
 @G_FILE_ERROR_TXTBSY: Text file busy.
diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c
index a02747c..f94bf31 100644
--- a/glib/gmappedfile.c
+++ b/glib/gmappedfile.c
@@ -112,14 +112,19 @@ g_mapped_file_destroy (GMappedFile *file)
  * Maps a file into memory. On UNIX, this is using the mmap() function.
  *
  * If @writable is %TRUE, the mapped buffer may be modified, otherwise
- * it is an error to modify the mapped buffer. Modifications to the buffer 
- * are not visible to other processes mapping the same file, and are not 
+ * it is an error to modify the mapped buffer. Modifications to the buffer
+ * are not visible to other processes mapping the same file, and are not
  * written back to the file.
  *
  * Note that modifications of the underlying file might affect the contents
- * of the #GMappedFile. Therefore, mapping should only be used if the file 
+ * of the #GMappedFile. Therefore, mapping should only be used if the file
  * will not be modified, or if all modifications of the file are done
- * atomically (e.g. using g_file_set_contents()). 
+ * atomically (e.g. using g_file_set_contents()).
+ *
+ * If @filename is the name of an empty, regular file, the function
+ * will successfully return an empty #GMappedFile. In other cases of
+ * size 0 (e.g. device files such as /dev/null), @error will be set
+ * to the #GFileError value #G_FILE_ERROR_INVAL.
  *
  * Return value: a newly allocated #GMappedFile which must be unref'd
  *    with g_mapped_file_unref(), or %NULL if the mapping failed.
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c
index 994af13..d6c6961 100644
--- a/glib/tests/mappedfile.c
+++ b/glib/tests/mappedfile.c
@@ -43,8 +43,8 @@ test_device (void)
   GMappedFile *file;
 
   file = g_mapped_file_new ("/dev/null", FALSE, &error);
+  g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL);
   g_assert (file == NULL);
-  g_assert (error != NULL);
   g_error_free (error);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]