1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| gboolean g_file_set_contents (const gchar *filename,
const gchar *contents,
gssize length,
GError **error);
Writes all of contents to a file named filename, with good error checking. If a file called filename already exists it will be overwritten.
This write is atomic in the sense that it is first written to a temporary file which is then renamed to the final name. Notes:
* On Unix, if filename already exists hard links to filename will break. Also since the file is recreated, existing permissions, access control lists, metadata etc. may be lost. If filename is a symbolic link, the link itself will be replaced, not the linked file.
* On Windows renaming a file will not remove an existing file with the new name, so on Windows there is a race condition between the existing file being removed and the temporary file being renamed.
* On Windows there is no way to remove a file that is open to some process, or mapped into memory. Thus, this function will fail if filename already exists and is open.
If the call was sucessful, it returns TRUE. If the call was not successful, it returns FALSE and sets error. The error domain is G_FILE_ERROR. Possible error codes are those in the GFileError enumeration.
filename :
name of a file to write contents to, in the GLib file name encoding
contents :
string to write to the file
length :
length of contents, or -1 if contents is a nul-terminated string
error :
return location for a GError, or NULL
Returns :
TRUE on success, FALSE if an error occurred
Since 2.8 |
Partager