MSVC 2010 Project Files: Split up the Property Sheets
[platform/upstream/glib.git] / glib / gmappedfile.c
index 57af411..7d241e7 100644 (file)
@@ -38,7 +38,9 @@
 #include <windows.h>
 #include <io.h>
 
+#undef fstat
 #define fstat(a,b) _fstati64(a,b)
+#undef stat
 #define stat _stati64
 
 #ifndef S_ISREG
@@ -56,7 +58,6 @@
 #include "gstdio.h"
 #include "gstrfuncs.h"
 #include "gatomic.h"
-#include "gbufferprivate.h"
 
 #include "glibintl.h"
 
 #define MAP_FAILED ((void *) -1)
 #endif
 
-struct _GMappedFile 
+/**
+ * GMappedFile:
+ *
+ * The #GMappedFile represents a file mapping created with
+ * g_mapped_file_new(). It has only private members and should
+ * not be accessed directly.
+ */
+
+struct _GMappedFile
 {
   gchar *contents;
   gsize  length;
@@ -80,16 +89,6 @@ struct _GMappedFile
 #endif
 };
 
-/* Make sure the layout of GMappedFile is the same as GBuffer's */
-G_STATIC_ASSERT (G_STRUCT_OFFSET (GMappedFile, contents) ==
-                 G_STRUCT_OFFSET (GBuffer, data));
-G_STATIC_ASSERT (G_STRUCT_OFFSET (GMappedFile, length) ==
-                 G_STRUCT_OFFSET (GBuffer, size));
-G_STATIC_ASSERT (G_STRUCT_OFFSET (GMappedFile, ref_count) ==
-                 G_STRUCT_OFFSET (GBuffer, ref_count));
-G_STATIC_ASSERT (G_STRUCT_OFFSET (GMappedFile, free_func) ==
-                 G_STRUCT_OFFSET (GBuffer, free_func));
-
 static void
 g_mapped_file_destroy (GMappedFile *file)
 {
@@ -296,7 +295,7 @@ g_mapped_file_new (const gchar  *filename,
  * Return value: a newly allocated #GMappedFile which must be unref'd
  *    with g_mapped_file_unref(), or %NULL if the mapping failed.
  *
- * Since: 2.30
+ * Since: 2.32
  */
 GMappedFile *
 g_mapped_file_new_from_fd (gint          fd,
@@ -403,3 +402,27 @@ g_mapped_file_unref (GMappedFile *file)
   if (g_atomic_int_dec_and_test (&file->ref_count))
     g_mapped_file_destroy (file);
 }
+
+/**
+ * g_mapped_file_get_bytes:
+ * @file: a #GMappedFile
+ *
+ * Creates a new #GBytes which references the data mapped from @file.
+ * The mapped contents of the file must not be modified after creating this
+ * bytes object, because a #GBytes should be immutable.
+ *
+ * Returns: (transfer full): A newly allocated #GBytes referencing data
+ *     from @file
+ *
+ * Since: 2.34
+ **/
+GBytes *
+g_mapped_file_get_bytes (GMappedFile *file)
+{
+  g_return_val_if_fail (file != NULL, NULL);
+
+  return g_bytes_new_with_free_func (file->contents,
+                                    file->length,
+                                    (GDestroyNotify) g_mapped_file_unref,
+                                    g_mapped_file_ref (file));
+}