mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
Don't use potentially incorrect errno in several places. (#165951)
2005-02-02 Tor Lillqvist <tml@novell.com> * glib/gfileutils.c: Don't use potentially incorrect errno in several places. (#165951) (g_mkstemp): Set errno appropriately.
This commit is contained in:
parent
92c4eebc05
commit
031ebdd193
@ -5,6 +5,10 @@
|
|||||||
wide-char or codepage strings on to C library functions, but bail
|
wide-char or codepage strings on to C library functions, but bail
|
||||||
out early. (#166084)
|
out early. (#166084)
|
||||||
|
|
||||||
|
* glib/gfileutils.c: Don't use potentially incorrect errno in
|
||||||
|
several places. (#165951)
|
||||||
|
(g_mkstemp): Set errno appropriately.
|
||||||
|
|
||||||
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gutils.c: Move doc comments inline.
|
* glib/gutils.c: Move doc comments inline.
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
wide-char or codepage strings on to C library functions, but bail
|
wide-char or codepage strings on to C library functions, but bail
|
||||||
out early. (#166084)
|
out early. (#166084)
|
||||||
|
|
||||||
|
* glib/gfileutils.c: Don't use potentially incorrect errno in
|
||||||
|
several places. (#165951)
|
||||||
|
(g_mkstemp): Set errno appropriately.
|
||||||
|
|
||||||
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gutils.c: Move doc comments inline.
|
* glib/gutils.c: Move doc comments inline.
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
wide-char or codepage strings on to C library functions, but bail
|
wide-char or codepage strings on to C library functions, but bail
|
||||||
out early. (#166084)
|
out early. (#166084)
|
||||||
|
|
||||||
|
* glib/gfileutils.c: Don't use potentially incorrect errno in
|
||||||
|
several places. (#165951)
|
||||||
|
(g_mkstemp): Set errno appropriately.
|
||||||
|
|
||||||
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gutils.c: Move doc comments inline.
|
* glib/gutils.c: Move doc comments inline.
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
wide-char or codepage strings on to C library functions, but bail
|
wide-char or codepage strings on to C library functions, but bail
|
||||||
out early. (#166084)
|
out early. (#166084)
|
||||||
|
|
||||||
|
* glib/gfileutils.c: Don't use potentially incorrect errno in
|
||||||
|
several places. (#165951)
|
||||||
|
(g_mkstemp): Set errno appropriately.
|
||||||
|
|
||||||
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
2005-02-02 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/gutils.c: Move doc comments inline.
|
* glib/gutils.c: Move doc comments inline.
|
||||||
|
@ -483,7 +483,10 @@ get_contents_stdio (const gchar *display_filename,
|
|||||||
|
|
||||||
while (!feof (f))
|
while (!feof (f))
|
||||||
{
|
{
|
||||||
|
int save_errno;
|
||||||
|
|
||||||
bytes = fread (buf, 1, 2048, f);
|
bytes = fread (buf, 1, 2048, f);
|
||||||
|
save_errno = errno;
|
||||||
|
|
||||||
while ((total_bytes + bytes + 1) > total_allocated)
|
while ((total_bytes + bytes + 1) > total_allocated)
|
||||||
{
|
{
|
||||||
@ -507,10 +510,10 @@ get_contents_stdio (const gchar *display_filename,
|
|||||||
{
|
{
|
||||||
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 (save_errno),
|
||||||
_("Error reading file '%s': %s"),
|
_("Error reading file '%s': %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -581,13 +584,15 @@ get_contents_regfile (const gchar *display_filename,
|
|||||||
{
|
{
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
g_free (buf);
|
g_free (buf);
|
||||||
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 (save_errno),
|
||||||
_("Failed to read from file '%s': %s"),
|
_("Failed to read from file '%s': %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -631,12 +636,14 @@ get_contents_posix (const gchar *filename,
|
|||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = 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 (save_errno),
|
||||||
_("Failed to open file '%s': %s"),
|
_("Failed to open file '%s': %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
g_free (display_filename);
|
g_free (display_filename);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -645,13 +652,15 @@ get_contents_posix (const gchar *filename,
|
|||||||
/* I don't think this will ever fail, aside from ENOMEM, but. */
|
/* I don't think this will ever fail, aside from ENOMEM, but. */
|
||||||
if (fstat (fd, &stat_buf) < 0)
|
if (fstat (fd, &stat_buf) < 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
close (fd);
|
close (fd);
|
||||||
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 (save_errno),
|
||||||
_("Failed to get attributes of file '%s': fstat() failed: %s"),
|
_("Failed to get attributes of file '%s': fstat() failed: %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
g_free (display_filename);
|
g_free (display_filename);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -678,12 +687,14 @@ get_contents_posix (const gchar *filename,
|
|||||||
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
|
int save_errno = 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 (save_errno),
|
||||||
_("Failed to open file '%s': fdopen() failed: %s"),
|
_("Failed to open file '%s': fdopen() failed: %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
g_free (display_filename);
|
g_free (display_filename);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -708,18 +719,20 @@ get_contents_win32 (const gchar *filename,
|
|||||||
gboolean retval;
|
gboolean retval;
|
||||||
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
|
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
|
||||||
gchar *display_filename = g_filename_display_name (filename);
|
gchar *display_filename = g_filename_display_name (filename);
|
||||||
|
int save_errno;
|
||||||
|
|
||||||
f = _wfopen (wfilename, L"rb");
|
f = _wfopen (wfilename, L"rb");
|
||||||
|
save_errno = errno;
|
||||||
g_free (wfilename);
|
g_free (wfilename);
|
||||||
|
|
||||||
if (f == NULL)
|
if (f == 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 (save_errno),
|
||||||
_("Failed to open file '%s': %s"),
|
_("Failed to open file '%s': %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
g_free (display_filename);
|
g_free (display_filename);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -842,7 +855,10 @@ g_mkstemp (gchar *tmpl)
|
|||||||
|
|
||||||
len = strlen (tmpl);
|
len = strlen (tmpl);
|
||||||
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
|
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is where the Xs start. */
|
/* This is where the Xs start. */
|
||||||
XXXXXX = &tmpl[len - 6];
|
XXXXXX = &tmpl[len - 6];
|
||||||
@ -881,6 +897,7 @@ g_mkstemp (gchar *tmpl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We got out of the loop because we ran out of combinations to try. */
|
/* We got out of the loop because we ran out of combinations to try. */
|
||||||
|
errno = EEXIST;
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -906,7 +923,10 @@ g_mkstemp (gchar *tmpl)
|
|||||||
|
|
||||||
len = strlen (tmpl);
|
len = strlen (tmpl);
|
||||||
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
|
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is where the Xs start. */
|
/* This is where the Xs start. */
|
||||||
XXXXXX = &tmpl[len - 6];
|
XXXXXX = &tmpl[len - 6];
|
||||||
@ -947,6 +967,7 @@ g_mkstemp (gchar *tmpl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We got out of the loop because we ran out of combinations to try. */
|
/* We got out of the loop because we ran out of combinations to try. */
|
||||||
|
errno = EEXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1041,12 +1062,14 @@ g_file_open_tmp (const gchar *tmpl,
|
|||||||
|
|
||||||
if (retval == -1)
|
if (retval == -1)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
gchar *display_fulltemplate = g_filename_display_name (fulltemplate);
|
gchar *display_fulltemplate = g_filename_display_name (fulltemplate);
|
||||||
|
|
||||||
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 (save_errno),
|
||||||
_("Failed to create file '%s': %s"),
|
_("Failed to create file '%s': %s"),
|
||||||
display_fulltemplate, g_strerror (errno));
|
display_fulltemplate, g_strerror (save_errno));
|
||||||
g_free (display_fulltemplate);
|
g_free (display_fulltemplate);
|
||||||
g_free (fulltemplate);
|
g_free (fulltemplate);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1416,14 +1439,16 @@ g_file_read_link (const gchar *filename,
|
|||||||
{
|
{
|
||||||
read_size = readlink (filename, buffer, size);
|
read_size = readlink (filename, buffer, size);
|
||||||
if (read_size < 0) {
|
if (read_size < 0) {
|
||||||
|
int save_errno = errno;
|
||||||
gchar *display_filename = g_filename_display_name (filename);
|
gchar *display_filename = g_filename_display_name (filename);
|
||||||
|
|
||||||
g_free (buffer);
|
g_free (buffer);
|
||||||
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 (save_errno),
|
||||||
_("Failed to read the symbolic link '%s': %s"),
|
_("Failed to read the symbolic link '%s': %s"),
|
||||||
display_filename,
|
display_filename,
|
||||||
g_strerror (errno));
|
g_strerror (save_errno));
|
||||||
g_free (display_filename);
|
g_free (display_filename);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user