#include <locale.h>
#include <glib.h>
#include <glib/gstdio.h>

#define TIMESTAMP 1000000000
#define EXPECTED_ru_RU_UTF8 "Вс"

int
main (int argc, char *argv[])
{
  GDateTime *stamp;
  gchar *str;
  gint i;
  struct tm *c_stamp;
  char buf[1024];
  time_t unix_time = TIMESTAMP;

  g_setenv ("LANG", "ru_RU", TRUE);

  stamp = g_date_time_new_from_unix_utc (unix_time);
  str = g_date_time_format (stamp, "%a");
  g_date_time_unref (stamp);

  g_print ("Glib UTF-8 output:\n");
  for (i = 0; str && ((guint8 *)str)[i]; i++)
    g_printf ("%u, ", ((guint8 *)str)[i]);
  g_printf ("\n");
  g_printf ("%s\n", str);
  g_free (str);

  setlocale (LC_ALL, ".1251");
  c_stamp = gmtime (&unix_time);
  strftime (buf, sizeof (buf), "%a", c_stamp);

  g_print ("\nlibc CP1251 output:\n");
  for (i = 0; ((guint8 *)buf)[i]; i++)
    g_printf ("%u, ", ((guint8 *)buf)[i]);
  g_printf ("\n");
  g_printf ("%s\n", buf);

  g_print ("\nexpected UTF-8 output:\n");
  str = (gchar *) EXPECTED_ru_RU_UTF8;
  for (i = 0; str && ((guint8 *)str)[i]; i++)
    g_printf ("%u, ", ((guint8 *)str)[i]);
  g_printf ("\n");
  g_printf ("%s\n", str);

  return 0;
}
