+_g_local_file_output_stream_open (const char *filename,
+ gboolean readable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ int open_flags;
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return NULL;
+
+ open_flags = O_BINARY;
+ if (readable)
+ open_flags |= O_RDWR;
+ else
+ open_flags |= O_WRONLY;
+
+ return output_stream_open (filename, open_flags, 0666, cancellable, error);
+}
+
+static gint
+mode_from_flags_or_info (GFileCreateFlags flags,
+ GFileInfo *reference_info)
+{
+ if (flags & G_FILE_CREATE_PRIVATE)
+ return 0600;
+ else if (reference_info && g_file_info_has_attribute (reference_info, "unix::mode"))
+ return g_file_info_get_attribute_uint32 (reference_info, "unix::mode") & (~S_IFMT);
+ else
+ return 0666;
+}
+
+GFileOutputStream *
+_g_local_file_output_stream_create (const char *filename,
+ gboolean readable,
+ GFileCreateFlags flags,
+ GFileInfo *reference_info,
+ GCancellable *cancellable,
+ GError **error)
+{
+ int mode;
+ int open_flags;
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return NULL;
+
+ mode = mode_from_flags_or_info (flags, reference_info);
+
+ open_flags = O_CREAT | O_EXCL | O_BINARY;
+ if (readable)
+ open_flags |= O_RDWR;
+ else
+ open_flags |= O_WRONLY;
+
+ return output_stream_open (filename, open_flags, mode, cancellable, error);
+}
+
+GFileOutputStream *