Method
GioFilereplace_contents
Declaration
gboolean
g_file_replace_contents (
GFile* file,
const char* contents,
gsize length,
const char* etag,
gboolean make_backup,
GFileCreateFlags flags,
char** new_etag,
GCancellable* cancellable,
GError** error
)
Description
Replaces the contents of file with contents of length bytes.
If etag is specified (not NULL), any existing file must have that etag,
or the error G_IO_ERROR_WRONG_ETAG will be returned.
If make_backup is TRUE, this function will attempt to make a backup
of file. Internally, it uses g_file_replace(), so will try to replace the
file contents in the safest way possible. For example, atomic renames are
used when replacing local files’ contents.
If cancellable is not NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
The returned new_etag can be used to verify that the file hasn’t
changed the next time it is saved over.
Parameters
contents-
Type: An array of
guint8A string containing the new contents for
file.The length of the array is specified in the lengthargument.The data is owned by the caller of the method. length-
Type:
gsizeThe length of
contentsin bytes. etag-
Type:
const char*The old entity-tag for the document, or
NULL.The argument can be NULL.The data is owned by the caller of the method. The value is a NUL terminated UTF-8 string. make_backup-
Type:
gbooleanTRUEif a backup should be created. flags-
Type:
GFileCreateFlagsA set of
GFileCreateFlags. new_etag-
Type:
char**A location to a new entity tag for the document. This should be freed with
g_free()when no longer needed, orNULL.The argument will be set by the function. The argument can be set to NULLby the method.The argument can be NULL.The caller of the method takes ownership of the returned data, and is responsible for freeing it. The value is a NUL terminated UTF-8 string. cancellable-
Type:
GCancellableOptional
GCancellableobject,NULLto ignore.The argument can be NULL.The data is owned by the caller of the method. error-
Type:
GError **The return location for a recoverable error.
The argument can be NULL.If the return location is not NULL, then you must initialize it to aNULLGError*.The argument will be left initialized to NULLby the method if there are no errors.In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.