* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#include "glibconfig.h"
+#ifdef G_OS_UNIX
+#include <unistd.h>
+#endif
+
#ifdef G_OS_WIN32
#include <windows.h>
#include <io.h>
+#undef fstat
#define fstat(a,b) _fstati64(a,b)
+#undef stat
#define stat _stati64
#ifndef S_ISREG
* 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
+ * Returns: a newly allocated #GMappedFile which must be unref'd
* with g_mapped_file_unref(), or %NULL if the mapping failed.
*
* Since: 2.8
* will not be modified, or if all modifications of the file are done
* atomically (e.g. using g_file_set_contents()).
*
- * Return value: a newly allocated #GMappedFile which must be unref'd
+ * Returns: 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,
* Increments the reference count of @file by one. It is safe to call
* this function from any thread.
*
- * Return value: the passed in #GMappedFile.
+ * Returns: the passed in #GMappedFile.
*
* Since: 2.22
**/
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));
+}