summaryrefslogtreecommitdiff
path: root/gtk/gtkcalendar.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2018-02-17 17:03:49 -0500
committerMatthias Clasen <mclasen@redhat.com>2018-02-17 17:12:45 -0500
commitf42ebef9d186ff87df2bbe0a37d7d14e58103577 (patch)
tree435e793ca47da5ffcd5fee1d9215cb9f2e0dd40e /gtk/gtkcalendar.c
parentcfcd0f888dafdcceacbf30e9aeae2e058858c81c (diff)
downloadgtk+-f42ebef9d186ff87df2bbe0a37d7d14e58103577.tar.gz
calendar: Avoid warnings for new "%OB" format
Use the same code we have in gtk-3-22 to deal with strftime() not supporting %OB, and avoid compiler warnings for non-literal format strings.
Diffstat (limited to 'gtk/gtkcalendar.c')
-rw-r--r--gtk/gtkcalendar.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index a93d92e384..f04a7c358c 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -634,6 +634,9 @@ gtk_calendar_class_init (GtkCalendarClass *class)
gtk_widget_class_set_css_name (widget_class, I_("calendar"));
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
static void
gtk_calendar_init (GtkCalendar *calendar)
{
@@ -644,6 +647,7 @@ gtk_calendar_init (GtkCalendar *calendar)
#ifdef G_OS_WIN32
wchar_t wbuffer[100];
#else
+ static const char *month_format = NULL;
char buffer[255];
time_t tmp_time;
#endif
@@ -703,8 +707,21 @@ gtk_calendar_init (GtkCalendar *calendar)
{
#ifndef G_OS_WIN32
tmp_time=i*2764800;
- /* Note: "%OB" works only in glibc >= 2.27 and in BSD and OS X. */
- strftime (buffer, sizeof (buffer), "%OB", gmtime (&tmp_time));
+ if (G_UNLIKELY (month_format == NULL))
+ {
+ buffer[0] = '\0';
+ month_format = "%OB";
+ strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
+ /* "%OB" is not supported in Linux with glibc < 2.27 */
+ if (!strcmp (buffer, "%OB") || !strcmp (buffer, "OB") || !strcmp (buffer, ""))
+ {
+ month_format = "%B";
+ strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
+ }
+ }
+ else
+ strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
+
default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
#else
if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
@@ -823,7 +840,8 @@ gtk_calendar_init (GtkCalendar *calendar)
calendar_compute_days (calendar);
}
-
+#pragma GCC diagnostic pop
+
/****************************************
* Utility Functions *
****************************************/