* its name indicates that it is executable, checking for well-known
* extensions and those listed in the `PATHEXT` environment variable.
*
- * Return value: whether a test was %TRUE
+ * Returns: whether a test was %TRUE
**/
gboolean
g_file_test (const gchar *filename,
* from a function that manipulates files. So you would use
* g_file_error_from_errno() when constructing a #GError.
*
- * Return value: #GFileError corresponding to the given @errno
+ * Returns: #GFileError corresponding to the given @errno
**/
GFileError
g_file_error_from_errno (gint err_no)
static char *
format_error_message (const gchar *filename,
- const gchar *format_string) G_GNUC_FORMAT(2);
+ const gchar *format_string,
+ int saved_errno) G_GNUC_FORMAT(2);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static char *
format_error_message (const gchar *filename,
- const gchar *format_string)
+ const gchar *format_string,
+ int saved_errno)
{
- gint saved_errno = errno;
gchar *display_name;
gchar *msg;
static void
set_file_error (GError **error,
const gchar *filename,
- const gchar *format_string)
+ const gchar *format_string,
+ int saved_errno)
{
- int saved_errno = errno;
- char *msg = format_error_message (filename, format_string);
+ char *msg = format_error_message (filename, format_string, saved_errno);
g_set_error_literal (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno),
msg);
if (fd < 0)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Failed to open file '%s': %s"));
+ _("Failed to open file '%s': %s"),
+ saved_errno);
return FALSE;
}
/* I don't think this will ever fail, aside from ENOMEM, but. */
if (fstat (fd, &stat_buf) < 0)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Failed to get attributes of file '%s': fstat() failed: %s"));
+ _("Failed to get attributes of file '%s': fstat() failed: %s"),
+ saved_errno);
close (fd);
return FALSE;
if (f == NULL)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Failed to open file '%s': fdopen() failed: %s"));
+ _("Failed to open file '%s': fdopen() failed: %s"),
+ saved_errno);
return FALSE;
}
if (f == NULL)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Failed to open file '%s': %s"));
+ _("Failed to open file '%s': %s"),
+ saved_errno);
return FALSE;
}
* codes are those in the #GFileError enumeration. In the error case,
* @contents is set to %NULL and @length is set to zero.
*
- * Return value: %TRUE on success, %FALSE if an error occurred
+ * Returns: %TRUE on success, %FALSE if an error occurred
**/
gboolean
g_file_get_contents (const gchar *filename,
if (fd == -1)
{
- set_file_error (err, tmp_name, _("Failed to create file '%s': %s"));
+ int saved_errno = errno;
+ set_file_error (err,
+ tmp_name, _("Failed to create file '%s': %s"),
+ saved_errno);
goto out;
}
if (s < 0)
{
- if (errno == EINTR)
+ int saved_errno = errno;
+ if (saved_errno == EINTR)
continue;
- set_file_error (err, tmp_name, _("Failed to write file '%s': write() failed: %s"));
+ set_file_error (err,
+ tmp_name, _("Failed to write file '%s': write() failed: %s"),
+ saved_errno);
close (fd);
g_unlink (tmp_name);
*/
if (g_lstat (dest_file, &statbuf) == 0 && statbuf.st_size > 0 && fsync (fd) != 0)
{
- set_file_error (err, tmp_name, _("Failed to write file '%s': fsync() failed: %s"));
+ int saved_errno = errno;
+ set_file_error (err,
+ tmp_name, _("Failed to write file '%s': fsync() failed: %s"),
+ saved_errno);
close (fd);
g_unlink (tmp_name);
* Note that the name for the temporary file is constructed by appending up
* to 7 characters to @filename.
*
- * Return value: %TRUE on success, %FALSE if an error occurred
+ * Returns: %TRUE on success, %FALSE if an error occurred
*
* Since: 2.8
*/
if (g_unlink (filename) == -1)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Existing file '%s' could not be removed: g_unlink() failed: %s"));
+ _("Existing file '%s' could not be removed: g_unlink() failed: %s"),
+ saved_errno);
g_unlink (tmp_filename);
retval = FALSE;
goto out;
* in the GLib file name encoding. Most importantly, on Windows it
* should be in UTF-8.
*
- * Return value: A pointer to @tmpl, which has been modified
+ * Returns: A pointer to @tmpl, which has been modified
* to hold the directory name. In case of errors, %NULL is
* returned, and %errno will be set.
*
* The string should be in the GLib file name encoding. Most importantly,
* on Windows it should be in UTF-8.
*
- * Return value: A pointer to @tmpl, which has been modified
+ * Returns: A pointer to @tmpl, which has been modified
* to hold the directory name. In case of errors, %NULL is
* returned and %errno will be set.
*
* The string should be in the GLib file name encoding. Most importantly,
* on Windows it should be in UTF-8.
*
- * Return value: A file handle (as from open()) to the file
+ * Returns: A file handle (as from open()) to the file
* opened for reading and writing. The file handle should be
* closed with close(). In case of errors, -1 is returned
* and %errno will be set.
* didn't exist. The string should be in the GLib file name encoding.
* Most importantly, on Windows it should be in UTF-8.
*
- * Return value: A file handle (as from open()) to the file
+ * Returns: A file handle (as from open()) to the file
* opened for reading and writing. The file is opened in binary
* mode on platforms where there is a difference. The file handle
* should be closed with close(). In case of errors, -1 is
retval = get_tmp_file (fulltemplate, f, flags, mode);
if (retval == -1)
{
+ int saved_errno = errno;
set_file_error (error,
fulltemplate,
- _("Failed to create file '%s': %s"));
+ _("Failed to create file '%s': %s"),
+ saved_errno);
g_free (fulltemplate);
return -1;
}
* when not needed any longer. The returned name is in the GLib file
* name encoding.
*
- * Return value: A file handle (as from open()) to the file opened for
+ * Returns: A file handle (as from open()) to the file opened for
* reading and writing. The file is opened in binary mode on platforms
* where there is a difference. The file handle should be closed with
* close(). In case of errors, -1 is returned and @error will be set.
* Note that in contrast to g_mkdtemp() (and mkdtemp()) @tmpl is not
* modified, and might thus be a read-only literal string.
*
- * Return value: (type filename): The actual name used. This string
+ * Returns: (type filename): The actual name used. This string
* should be freed with g_free() when not needed any longer and is
* is in the GLib file name encoding. In case of errors, %NULL is
* returned and @error will be set.
* as a string array, instead of varargs. This function is mainly
* meant for language bindings.
*
- * Return value: a newly-allocated string that must be freed with g_free().
+ * Returns: a newly-allocated string that must be freed with g_free().
*
* Since: 2.8
*/
* copies of the separator, elements consisting only of copies
* of the separator are ignored.
*
- * Return value: a newly-allocated string that must be freed with g_free().
+ * Returns: a newly-allocated string that must be freed with g_free().
**/
gchar *
g_build_path (const gchar *separator,
* as a string array, instead of varargs. This function is mainly
* meant for language bindings.
*
- * Return value: a newly-allocated string that must be freed with g_free().
+ * Returns: a newly-allocated string that must be freed with g_free().
*
* Since: 2.8
*/
* path. If the first element is a relative path, the result will
* be a relative path.
*
- * Return value: a newly-allocated string that must be freed with g_free().
+ * Returns: a newly-allocated string that must be freed with g_free().
**/
gchar *
g_build_filename (const gchar *first_element,
read_size = readlink (filename, buffer, size);
if (read_size < 0)
{
+ int saved_errno = errno;
set_file_error (error,
filename,
- _("Failed to read the symbolic link '%s': %s"));
-
+ _("Failed to read the symbolic link '%s': %s"),
+ saved_errno);
+ g_free (buffer);
return NULL;
}
* components. It returns a pointer into the given file name
* string.
*
- * Return value: the name of the file without any leading
+ * Returns: the name of the file without any leading
* directory components
*
* Deprecated:2.2: Use g_path_get_basename() instead, but notice
* separators (and on Windows, possibly a drive letter), a single
* separator is returned. If @file_name is empty, it gets ".".
*
- * Return value: a newly allocated string containing the last
+ * Returns: a newly allocated string containing the last
* component of the filename
*/
gchar *