No need to have two variants of errno-to-GError

This commit is contained in:
Matthias Clasen 2011-06-05 22:20:18 -04:00
parent d811f0cdc9
commit a79a5a6202

View File

@ -50,20 +50,8 @@ g_unix_error_quark (void)
} }
static gboolean static gboolean
g_unix_set_error_from_errno (GError **error) g_unix_set_error_from_errno (GError **error,
{ gint saved_errno)
int saved_errno = errno;
g_set_error_literal (error,
G_UNIX_ERROR,
0,
g_strerror (errno));
errno = saved_errno;
return FALSE;
}
static gboolean
g_unix_set_error_from_errno_saved (GError **error,
int saved_errno)
{ {
g_set_error_literal (error, g_set_error_literal (error,
G_UNIX_ERROR, G_UNIX_ERROR,
@ -111,7 +99,7 @@ g_unix_open_pipe (int *fds,
/* Atomic */ /* Atomic */
ecode = pipe2 (fds, pipe2_flags); ecode = pipe2 (fds, pipe2_flags);
if (ecode == -1 && errno != ENOSYS) if (ecode == -1 && errno != ENOSYS)
return g_unix_set_error_from_errno (error); return g_unix_set_error_from_errno (error, errno);
else if (ecode == 0) else if (ecode == 0)
return TRUE; return TRUE;
/* Fall through on -ENOSYS, we must be running on an old kernel */ /* Fall through on -ENOSYS, we must be running on an old kernel */
@ -119,13 +107,13 @@ g_unix_open_pipe (int *fds,
#endif #endif
ecode = pipe (fds); ecode = pipe (fds);
if (ecode == -1) if (ecode == -1)
return g_unix_set_error_from_errno (error); return g_unix_set_error_from_errno (error, errno);
ecode = fcntl (fds[0], flags); ecode = fcntl (fds[0], flags);
if (ecode == -1) if (ecode == -1)
{ {
int saved_errno = errno; int saved_errno = errno;
close (fds[0]); close (fds[0]);
return g_unix_set_error_from_errno_saved (error, saved_errno); return g_unix_set_error_from_errno (error, saved_errno);
} }
ecode = fcntl (fds[0], flags); ecode = fcntl (fds[0], flags);
if (ecode == -1) if (ecode == -1)
@ -133,7 +121,7 @@ g_unix_open_pipe (int *fds,
int saved_errno = errno; int saved_errno = errno;
close (fds[0]); close (fds[0]);
close (fds[1]); close (fds[1]);
return g_unix_set_error_from_errno_saved (error, saved_errno); return g_unix_set_error_from_errno (error, saved_errno);
} }
return TRUE; return TRUE;
} }
@ -162,7 +150,7 @@ g_unix_set_fd_nonblocking (gint fd,
fcntl_flags = fcntl (fd, F_GETFL); fcntl_flags = fcntl (fd, F_GETFL);
if (fcntl_flags == -1) if (fcntl_flags == -1)
return g_unix_set_error_from_errno (error); return g_unix_set_error_from_errno (error, errno);
if (nonblock) if (nonblock)
{ {
@ -182,10 +170,10 @@ g_unix_set_fd_nonblocking (gint fd,
} }
if (fcntl (fd, F_SETFL, fcntl_flags) == -1) if (fcntl (fd, F_SETFL, fcntl_flags) == -1)
return g_unix_set_error_from_errno (error); return g_unix_set_error_from_errno (error, errno);
return TRUE; return TRUE;
#else #else
return g_unix_set_error_from_errno_saved (error, EINVAL); return g_unix_set_error_from_errno (error, EINVAL);
#endif #endif
} }