summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gsystem-file-utils.c56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/gsystem-file-utils.c b/src/gsystem-file-utils.c
index 63cd24d..e507d21 100644
--- a/src/gsystem-file-utils.c
+++ b/src/gsystem-file-utils.c
@@ -72,11 +72,11 @@ open_nointr (const char *path, int flags, mode_t mode)
}
static inline void
-_set_error_from_errno (GError **error)
+_set_error_from_errno (const char *prefix, GError **error)
{
int errsv = errno;
- g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errsv),
- g_strerror (errsv));
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
+ "%s: %s", prefix, g_strerror (errsv));
}
/**
@@ -113,7 +113,7 @@ gs_file_openat_noatime (int dfd,
if (fd == -1)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("openat", error);
return FALSE;
}
else
@@ -192,7 +192,7 @@ gs_stream_fstat (GFileDescriptorBased *stream,
if (fstat (fd, stbuf) == -1)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("fstat", error);
goto out;
}
@@ -304,14 +304,14 @@ gs_file_sync_data (GFile *file,
while (G_UNLIKELY (res != 0 && errno == EINTR));
if (res != 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("fdatasync", error);
goto out;
}
res = close_nointr (fd);
if (res != 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("close", error);
goto out;
}
fd = -1;
@@ -348,14 +348,14 @@ gs_file_create (GFile *file,
fd = open_nointr (gs_file_get_path_cached (file), O_WRONLY | O_CREAT | O_EXCL, mode);
if (fd < 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("open", error);
goto out;
}
if (fchmod (fd, mode) < 0)
{
close (fd);
- _set_error_from_errno (error);
+ _set_error_from_errno ("fchmod", error);
goto out;
}
@@ -457,7 +457,7 @@ gs_file_open_dir_fd (GFile *path,
*out_fd = open (gs_file_get_path_cached (path), O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC);
if (*out_fd == -1)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("open", error);
return FALSE;
}
return TRUE;
@@ -485,7 +485,7 @@ gs_file_open_dir_fd_at (int parent_dfd,
*out_fd = openat (parent_dfd, name, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC);
if (*out_fd == -1)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("openat", error);
return FALSE;
}
return TRUE;
@@ -530,7 +530,7 @@ gs_file_open_in_tmpdir_at (int tmpdir_fd,
while (fd == -1 && errno == EINTR);
if (fd < 0 && errno != EEXIST)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("openat", error);
goto out;
}
else if (fd != -1)
@@ -585,7 +585,7 @@ gs_file_open_in_tmpdir (GFile *tmpdir,
d = opendir (gs_file_get_path_cached (tmpdir));
if (!d)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("opendir", error);
goto out;
}
dfd = dirfd (d);
@@ -646,7 +646,7 @@ linkcopy_internal_attempt (GFile *src,
}
else
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("link", error);
goto out;
}
}
@@ -1006,7 +1006,7 @@ gs_file_rename (GFile *from,
if (rename (gs_file_get_path_cached (from),
gs_file_get_path_cached (to)) < 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("rename", error);
return FALSE;
}
return TRUE;
@@ -1035,7 +1035,7 @@ gs_file_unlink (GFile *path,
if (unlink (gs_file_get_path_cached (path)) < 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("unlink", error);
return FALSE;
}
return TRUE;
@@ -1064,7 +1064,7 @@ chown_internal (GFile *path,
if (res < 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("chown", error);
goto out;
}
@@ -1146,7 +1146,7 @@ gs_file_chmod (GFile *path,
if (res < 0)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("chmod", error);
goto out;
}
@@ -1227,7 +1227,7 @@ gs_file_ensure_directory_mode (GFile *dir,
if (mkdir (gs_file_get_path_cached (dir), mode) == -1 && errno != EEXIST)
{
- _set_error_from_errno (error);
+ _set_error_from_errno ("mkdir", error);
return FALSE;
}
return TRUE;
@@ -1437,8 +1437,7 @@ read_xattr_name_array (const char *path,
bytes_read = lgetxattr (path, p, NULL, 0);
if (bytes_read < 0)
{
- _set_error_from_errno (error);
- g_prefix_error (error, "lgetxattr (%s, %s) failed: ", path, p);
+ _set_error_from_errno ("lgetxattr", error);
goto out;
}
if (bytes_read == 0)
@@ -1449,8 +1448,7 @@ read_xattr_name_array (const char *path,
if (lgetxattr (path, p, buf, bytes_read) < 0)
{
g_bytes_unref (bytes);
- _set_error_from_errno (error);
- g_prefix_error (error, "lgetxattr (%s, %s) failed: ", path, p);
+ _set_error_from_errno ("lgetxattr", error);
goto out;
}
@@ -1489,8 +1487,7 @@ get_xattrs_impl (GFile *f,
{
if (errno != ENOTSUP)
{
- _set_error_from_errno (error);
- g_prefix_error (error, "llistxattr (%s) failed: ", path);
+ _set_error_from_errno ("llistxattr", error);
goto out;
}
}
@@ -1499,8 +1496,7 @@ get_xattrs_impl (GFile *f,
xattr_names = g_malloc (bytes_read);
if (llistxattr (path, xattr_names, bytes_read) < 0)
{
- _set_error_from_errno (error);
- g_prefix_error (error, "llistxattr (%s) failed: ", path);
+ _set_error_from_errno ("llistxattr", error);
goto out;
}
xattr_names_canonical = canonicalize_xattrs (xattr_names, bytes_read);
@@ -1603,8 +1599,7 @@ gs_fd_set_all_xattrs (int fd,
g_variant_unref (value);
if (G_UNLIKELY (res == -1))
{
- _set_error_from_errno (error);
- g_prefix_error (error, "fsetxattr: ");
+ _set_error_from_errno ("fsetxattr", error);
goto out;
}
}
@@ -1644,8 +1639,7 @@ set_all_xattrs_for_path (const char *path,
g_clear_pointer (&value, (GDestroyNotify) g_variant_unref);
if (loop_err)
{
- _set_error_from_errno (error);
- g_prefix_error (error, "lsetxattr: ");
+ _set_error_from_errno ("lsetxattr", error);
goto out;
}
}