mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-10 12:55:48 +01:00
Merge branch 'backport-2910-fputs-result-glib-2-74' into 'glib-2-74'
Backport !2910 “gmessages: Handle unused results from fputs and fwrite” to glib-2-74 See merge request GNOME/glib!2983
This commit is contained in:
commit
1936516268
@ -601,7 +601,12 @@ static void
|
|||||||
write_string (FILE *stream,
|
write_string (FILE *stream,
|
||||||
const gchar *string)
|
const gchar *string)
|
||||||
{
|
{
|
||||||
fputs (string, stream);
|
if (fputs (string, stream) == EOF)
|
||||||
|
{
|
||||||
|
/* Something failed, but it's not an error we can handle at glib level
|
||||||
|
* so let's just continue without the compiler blaming us
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -612,8 +617,12 @@ write_string_sized (FILE *stream,
|
|||||||
/* Is it nul-terminated? */
|
/* Is it nul-terminated? */
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
write_string (stream, string);
|
write_string (stream, string);
|
||||||
else
|
else if (fwrite (string, 1, length, stream) < (size_t) length)
|
||||||
fwrite (string, 1, length, stream);
|
{
|
||||||
|
/* Something failed, but it's not an error we can handle at glib level
|
||||||
|
* so let's just continue without the compiler blaming us
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLogDomain*
|
static GLogDomain*
|
||||||
@ -3330,6 +3339,35 @@ g_set_print_handler (GPrintFunc func)
|
|||||||
return old_print_func;
|
return old_print_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_string (FILE *stream,
|
||||||
|
const gchar *string)
|
||||||
|
{
|
||||||
|
const gchar *charset;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (g_get_console_charset (&charset))
|
||||||
|
{
|
||||||
|
/* charset is UTF-8 already */
|
||||||
|
ret = fputs (string, stream);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gchar *converted_string = strdup_convert (string, charset);
|
||||||
|
|
||||||
|
ret = fputs (converted_string, stream);
|
||||||
|
g_free (converted_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* In case of failure we can just return early, but there's nothing else
|
||||||
|
* we can do at this level
|
||||||
|
*/
|
||||||
|
if (ret == EOF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fflush (stream);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_print:
|
* g_print:
|
||||||
* @format: the message format. See the printf() documentation
|
* @format: the message format. See the printf() documentation
|
||||||
@ -3367,20 +3405,8 @@ g_print (const gchar *format,
|
|||||||
if (local_glib_print_func)
|
if (local_glib_print_func)
|
||||||
local_glib_print_func (string);
|
local_glib_print_func (string);
|
||||||
else
|
else
|
||||||
{
|
print_string (stdout, string);
|
||||||
const gchar *charset;
|
|
||||||
|
|
||||||
if (g_get_console_charset (&charset))
|
|
||||||
fputs (string, stdout); /* charset is UTF-8 already */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gchar *lstring = strdup_convert (string, charset);
|
|
||||||
|
|
||||||
fputs (lstring, stdout);
|
|
||||||
g_free (lstring);
|
|
||||||
}
|
|
||||||
fflush (stdout);
|
|
||||||
}
|
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3446,20 +3472,8 @@ g_printerr (const gchar *format,
|
|||||||
if (local_glib_printerr_func)
|
if (local_glib_printerr_func)
|
||||||
local_glib_printerr_func (string);
|
local_glib_printerr_func (string);
|
||||||
else
|
else
|
||||||
{
|
print_string (stderr, string);
|
||||||
const gchar *charset;
|
|
||||||
|
|
||||||
if (g_get_console_charset (&charset))
|
|
||||||
fputs (string, stderr); /* charset is UTF-8 already */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gchar *lstring = strdup_convert (string, charset);
|
|
||||||
|
|
||||||
fputs (lstring, stderr);
|
|
||||||
g_free (lstring);
|
|
||||||
}
|
|
||||||
fflush (stderr);
|
|
||||||
}
|
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user