Preserve errno

When using errno in g_set_error with _(), preserve errno. Bug #592457.
This commit is contained in:
Christian Persch 2009-08-20 15:13:43 +02:00
parent feff29aefc
commit 8ef30758d5
4 changed files with 49 additions and 22 deletions

View File

@ -633,10 +633,13 @@ g_convert_with_iconv (const gchar *str,
have_error = TRUE; have_error = TRUE;
break; break;
default: default:
if (error) {
int errsv = errno;
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
_("Error during conversion: %s"), _("Error during conversion: %s"),
g_strerror (errno)); g_strerror (errsv));
}
have_error = TRUE; have_error = TRUE;
break; break;
} }
@ -940,9 +943,14 @@ g_convert_with_fallback (const gchar *str,
} }
/* fall thru if p is NULL */ /* fall thru if p is NULL */
default: default:
{
int errsv = errno;
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED, g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
_("Error during conversion: %s"), _("Error during conversion: %s"),
g_strerror (errno)); g_strerror (errsv));
}
have_error = TRUE; have_error = TRUE;
break; break;
} }

View File

@ -80,6 +80,7 @@ g_dir_open (const gchar *path,
GError **error) GError **error)
{ {
GDir *dir; GDir *dir;
int errsv;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
wchar_t *wpath; wchar_t *wpath;
#else #else
@ -103,12 +104,13 @@ g_dir_open (const gchar *path,
return dir; return dir;
/* error case */ /* error case */
errsv = errno;
g_set_error (error, g_set_error (error,
G_FILE_ERROR, G_FILE_ERROR,
g_file_error_from_errno (errno), g_file_error_from_errno (errsv),
_("Error opening directory '%s': %s"), _("Error opening directory '%s': %s"),
path, g_strerror (errno)); path, g_strerror (errsv));
g_free (dir); g_free (dir);
@ -122,13 +124,16 @@ g_dir_open (const gchar *path,
return dir; return dir;
/* error case */ /* error case */
errsv = errno;
utf8_path = g_filename_to_utf8 (path, -1, utf8_path = g_filename_to_utf8 (path, -1,
NULL, NULL, NULL); NULL, NULL, NULL);
g_set_error (error, g_set_error (error,
G_FILE_ERROR, G_FILE_ERROR,
g_file_error_from_errno (errno), g_file_error_from_errno (errsv),
_("Error opening directory '%s': %s"), _("Error opening directory '%s': %s"),
utf8_path, g_strerror (errno)); utf8_path, g_strerror (errsv));
g_free (utf8_path); g_free (utf8_path);
g_free (dir); g_free (dir);

View File

@ -294,9 +294,11 @@ make_pipe (gint p[2],
{ {
if (_pipe (p, 4096, _O_BINARY) < 0) if (_pipe (p, 4096, _O_BINARY) < 0)
{ {
int errsv = errno;
g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
_("Failed to create pipe for communicating with child process (%s)"), _("Failed to create pipe for communicating with child process (%s)"),
g_strerror (errno)); g_strerror (errsv));
return FALSE; return FALSE;
} }
else else
@ -330,11 +332,12 @@ read_helper_report (int fd,
if (chunk < 0) if (chunk < 0)
{ {
/* Some weird shit happened, bail out */ int errsv = errno;
/* Some weird shit happened, bail out */
g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
_("Failed to read from child pipe (%s)"), _("Failed to read from child pipe (%s)"),
g_strerror (errno)); g_strerror (errsv));
return FALSE; return FALSE;
} }

View File

@ -182,11 +182,13 @@ read_data (GString *str,
goto again; goto again;
else if (bytes < 0) else if (bytes < 0)
{ {
int errsv = errno;
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_READ, G_SPAWN_ERROR_READ,
_("Failed to read data from child process (%s)"), _("Failed to read data from child process (%s)"),
g_strerror (errno)); g_strerror (errsv));
return READ_FAILED; return READ_FAILED;
} }
@ -317,13 +319,15 @@ g_spawn_sync (const gchar *working_directory,
if (ret < 0 && errno != EINTR) if (ret < 0 && errno != EINTR)
{ {
int errsv = errno;
failed = TRUE; failed = TRUE;
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_READ, G_SPAWN_ERROR_READ,
_("Unexpected error in select() reading data from a child process (%s)"), _("Unexpected error in select() reading data from a child process (%s)"),
g_strerror (errno)); g_strerror (errsv));
break; break;
} }
@ -400,13 +404,15 @@ g_spawn_sync (const gchar *working_directory,
{ {
if (!failed) /* avoid error pileups */ if (!failed) /* avoid error pileups */
{ {
int errsv = errno;
failed = TRUE; failed = TRUE;
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_READ, G_SPAWN_ERROR_READ,
_("Unexpected error in waitpid() (%s)"), _("Unexpected error in waitpid() (%s)"),
g_strerror (errno)); g_strerror (errsv));
} }
} }
} }
@ -1124,13 +1130,14 @@ read_ints (int fd,
if (chunk < 0) if (chunk < 0)
{ {
/* Some weird shit happened, bail out */ int errsv = errno;
/* Some weird shit happened, bail out */
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_FAILED, G_SPAWN_ERROR_FAILED,
_("Failed to read from child pipe (%s)"), _("Failed to read from child pipe (%s)"),
g_strerror (errno)); g_strerror (errsv));
return FALSE; return FALSE;
} }
@ -1191,11 +1198,13 @@ fork_exec_with_pipes (gboolean intermediate_child,
if (pid < 0) if (pid < 0)
{ {
int errsv = errno;
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_FORK, G_SPAWN_ERROR_FORK,
_("Failed to fork (%s)"), _("Failed to fork (%s)"),
g_strerror (errno)); g_strerror (errsv));
goto cleanup_and_fail; goto cleanup_and_fail;
} }
@ -1390,11 +1399,13 @@ fork_exec_with_pipes (gboolean intermediate_child,
if (n_ints < 1) if (n_ints < 1)
{ {
int errsv = errno;
g_set_error (error, g_set_error (error,
G_SPAWN_ERROR, G_SPAWN_ERROR,
G_SPAWN_ERROR_FAILED, G_SPAWN_ERROR_FAILED,
_("Failed to read enough data from child pid pipe (%s)"), _("Failed to read enough data from child pid pipe (%s)"),
g_strerror (errno)); g_strerror (errsv));
goto cleanup_and_fail; goto cleanup_and_fail;
} }
else else