Example #1
0
gchar *gfire_game_get_version_str()
{
	time_t version = gfire_games_version;
	struct tm *time_data = localtime(&version);

	gchar *local_str = g_malloc(100 * sizeof(gchar));
	strftime(local_str, 100, "%d %B %Y", time_data);

	gchar *ret = g_locale_to_utf8(local_str, -1, NULL, NULL, NULL);
	g_free(local_str);

	if(!ret)
		return g_strdup(_("Unknown"));

	return ret;
}
Example #2
0
gboolean
g_file_test (const gchar *filename,
             GFileTest    test)
{
  gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
  gboolean retval;

  if (utf8_filename == NULL)
    return FALSE;

  retval = g_file_test_utf8 (utf8_filename, test);

  g_free (utf8_filename);

  return retval;
}
Example #3
0
gchar *
qof_formatted_time_to_utf8(const gchar *locale_string)
{
    gchar *retval;
    GError *error = NULL;

    retval = g_locale_to_utf8(locale_string, -1, NULL, NULL, &error);

    if (!retval)
    {
        g_warning("Could not convert '%s' to UTF-8: %s", locale_string,
                  error->message);
        g_error_free(error);
    }
    return retval;
}
Example #4
0
static char *
exif_string_to_utf8 (const char *exif_str)
{
	char *utf8_str;
	
	if (g_utf8_validate (exif_str, -1, NULL)) {
		return g_strdup (exif_str);
	}
	
	utf8_str = g_locale_to_utf8 (exif_str, -1, NULL, NULL, NULL);
	if (utf8_str != NULL) {
		return utf8_str;
	}
	
	return eel_make_valid_utf8 (exif_str);
}
Example #5
0
/* {{{ proto string Glib::localeToUtf8(string text)
	   Converts a string which is in the encoding used for strings in the current locale into a UTF-8 string. 
   */
PHP_METHOD(Glib, localeToUtf8)
{
	char *str_utf8, *locale;
	int length;
	GError *error = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &locale, &length) == FAILURE) {
		return;
	}

	str_utf8 = g_locale_to_utf8((const gchar*)locale, length, NULL, NULL, &error);
	if (php_glib_handle_gerror(&error TSRMLS_CC)) {
		return;
	}
	RETURN_STRING(str_utf8, 1);
}
static gchar *
ogg_get_comment (vorbis_comment *vc,
                 const gchar    *label)
{
	gchar *tag;
	gchar *utf_tag;

	if (vc && (tag = vorbis_comment_query (vc, label, 0)) != NULL) {
		utf_tag = g_locale_to_utf8 (tag, -1, NULL, NULL, NULL);
		/*g_free (tag);*/

		return utf_tag;
	} else {
		return NULL;
	}
}
Example #7
0
/*
Affichage boite de dialog "nouveau"
@params	p_widget	Elément ayant déclencher la fonction
@params	user_data	Données transmis au callback
*/
void cb_new_dialog(GtkWidget *p_widget, gpointer user_data){
    GtkWidget *p_dialog = gtk_dialog_new_with_buttons("Nouveau",
                                                        GTK_WINDOW(widgetCallback.entry1),
                                                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                        "Rentrer la grille manuellement",
                                                        GTK_RESPONSE_ACCEPT,
                                                        g_locale_to_utf8("Générer automatiquement", -1, NULL, NULL, NULL),
                                                        GTK_RESPONSE_REJECT,
                                                        NULL);
    gtk_widget_show(p_dialog);

    g_signal_connect_swapped(p_dialog, "response", G_CALLBACK(cb_new), p_dialog);

    //Parametres inutilises
    (void)p_widget;
}
Example #8
0
void
_gtk_entry_set_locale_text (GtkEntry   *entry,
			    const char *text)
{
	char *utf8_text;

	if (text == NULL)
		return;

	utf8_text = g_locale_to_utf8 (text, -1, NULL, NULL, NULL);
	if (utf8_text != NULL)
		gtk_entry_set_text (entry, utf8_text);
	else
		gtk_entry_set_text (entry, "");
	g_free (utf8_text);
}
Example #9
0
static int
StatHostTime(void)
{
   int64 hostSecs;
   int64 hostUsecs;
   time_t sec;
   char buf[256];
   gchar *timeUtf8;
   Backdoor_proto bp;

   bp.in.cx.halfs.low = BDOOR_CMD_GETTIMEFULL;
   Backdoor(&bp);
   if (bp.out.ax.word == BDOOR_MAGIC) {
      hostSecs = ((uint64)bp.out.si.word << 32) | bp.out.dx.word;
   } else {
      /* Falling back to older command. */
      bp.in.cx.halfs.low = BDOOR_CMD_GETTIME;
      Backdoor(&bp);
      hostSecs = bp.out.ax.word;
   }
   hostUsecs = bp.out.bx.word;

   if (hostSecs <= 0) {
      ToolsCmd_PrintErr("%s",
                        SU_(stat.gettime.failed, "Unable to get host time.\n"));
      return EX_TEMPFAIL;
   }

   sec = hostSecs + (hostUsecs / 1000000);
   if (strftime(buf, sizeof buf, "%d %b %Y %H:%M:%S", localtime(&sec)) == 0) {
      ToolsCmd_PrintErr("%s",
                        SU_(stat.formattime.failed, "Unable to format host time.\n"));
      return EX_TEMPFAIL;
   }

   timeUtf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
   if (timeUtf8 == NULL) {
      ToolsCmd_PrintErr("%s",
                        SU_(stat.formattime.failed, "Unable to format host time.\n"));
      return EX_TEMPFAIL;
   }

   g_print("%s\n", timeUtf8);
   g_free(timeUtf8);
   return EXIT_SUCCESS;
}
Example #10
0
void _init_keynodes_str()
{
    gsize bytes_read = 0, bytes_written = 0;
    sc_uint32 i = 0;

    keynodes_str = g_new0(gchar*, SC_KEYNODE_COUNT);
    keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER] = g_locale_to_utf8("nrel_system_identifier", -1, &bytes_read, &bytes_written, 0);


    // check for errors
    for (i = 0; i < (sc_uint32)SC_KEYNODE_COUNT; ++i)
    {
        if (keynodes_str[(sc_keynode)i] == null_ptr)
            g_error("Error to create string representation of keynode: %d", i);
    }

}
Example #11
0
GDir *
g_dir_open (const gchar  *path,
            guint         flags,
            GError      **error)
{
  gchar *utf8_path = g_locale_to_utf8 (path, -1, NULL, NULL, error);
  GDir *retval;

  if (utf8_path == NULL)
    return NULL;

  retval = g_dir_open_utf8 (utf8_path, flags, error);

  g_free (utf8_path);

  return retval;
}
Example #12
0
static gchar *time_to_string_format (time_t t, const gchar *format)
{
    gchar buf[PATH_MAX+1];
    struct tm tm;
    size_t size;

    g_return_val_if_fail (format, NULL);

    if (t)
    {
	localtime_r (&t, &tm);
	size = strftime (buf, PATH_MAX, format, &tm);
	buf[size] = 0;
	return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
    }
    return g_strdup ("--");
}
Example #13
0
void
data_window_add(struct data_window *win, struct param_list *param, int count)
{
	int i;
	GtkCellRenderer *cell;
	GtkTreeIter iter;
	GtkListStore *liststore;
	GType types[count];
	gchar *utf8;

	if (! win->treeview) {
		win->treeview=gtk_tree_view_new();
		gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), NULL);
		gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(win->scrolled_window),win->treeview);
		gtk_widget_show_all(GTK_WIDGET(win->window));
		/* add column names to treeview */
		for(i=0;i<count;i++) {
			cell=gtk_cell_renderer_text_new();
			gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (win->treeview),-1,param[i].name,
					cell,"text",i, NULL);
		}
	}

	/* find data storage and create a new one if none is there */
	if (gtk_tree_view_get_model(GTK_TREE_VIEW (win->treeview)) == NULL) {
		for(i=0;i<count;i++) types[i]=G_TYPE_STRING;
	    	liststore=gtk_list_store_newv(count,types);
		gtk_tree_view_set_model (GTK_TREE_VIEW (win->treeview), GTK_TREE_MODEL(liststore));
	}
	else
		liststore=GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (win->treeview)));

	gtk_list_store_append(liststore,&iter);

	/* add data to data storage */
	for(i=0;i<count;i++) {
		utf8=g_locale_to_utf8(param[i].value,-1,NULL,NULL,NULL);
		gtk_list_store_set(liststore,&iter,i,utf8,-1);
	}

#if 0
		g_signal_connect(G_OBJECT(win->clist), "click-column", G_CALLBACK(click_column), NULL);
		g_signal_connect(G_OBJECT(win->clist), "select-row", G_CALLBACK(select_row), win);
#endif
}
Example #14
0
/**
 * mono_utf8_from_external:
 * @in: pointer to the string buffer.
 *
 * Tries to turn a NULL-terminated string into UTF8.
 *
 * First, see if it's valid UTF8, in which case there's nothing more
 * to be done.  Next, run through the colon-separated encodings in
 * MONO_EXTERNAL_ENCODINGS and do an iconv conversion on each,
 * returning the first successful conversion to utf8.  If no
 * conversion succeeds, return NULL.
 *
 * Callers must free the returned string if not NULL.
 *
 * This function is identical to mono_unicode_from_external, apart
 * from returning utf8 not utf16; it's handy in a few places to work
 * in utf8.
 */
gchar *mono_utf8_from_external (const gchar *in)
{
	gchar *res=NULL;
	gchar **encodings;
	const gchar *encoding_list;
	int i;
	
	if(in==NULL) {
		return(NULL);
	}
	
	encoding_list=g_getenv ("MONO_EXTERNAL_ENCODINGS");
	if(encoding_list==NULL) {
		encoding_list = "";
	}
	
	encodings=g_strsplit (encoding_list, ":", 0);
	for(i=0;encodings[i]!=NULL; i++) {
		
		/* "default_locale" is a special case encoding */
		if(!strcmp (encodings[i], "default_locale")) {
			res=g_locale_to_utf8 (in, -1, NULL, NULL, NULL);
			if(res!=NULL && !g_utf8_validate (res, -1, NULL)) {
				g_free (res);
				res=NULL;
			}
		} else {
			res=g_convert (in, -1, "UTF8", encodings[i], NULL,
				       NULL, NULL);
		}

		if(res!=NULL) {
			g_strfreev (encodings);
			return(res);
		}
	}
	
	g_strfreev (encodings);
	
	if(g_utf8_validate (in, -1, NULL)) {
		return(g_strdup (in));
	}

	return(NULL);
}
Example #15
0
static gchar *
validate_vcard_string(gchar * vcstr)
{
    gchar * utf8res;
    gsize b_written;

    /* check if it's a utf8 clean string and return it in this case */
    if (!vcstr || g_utf8_validate(vcstr, -1, NULL))
        return vcstr;

    /* try to convert from the user's locale setting */
    utf8res = g_locale_to_utf8(vcstr, -1, NULL, &b_written, NULL);
    if (!utf8res)
        return vcstr;

    g_free(vcstr);
    return utf8res;
}
Example #16
0
gboolean
g_file_get_contents (const gchar *filename,
                     gchar      **contents,
                     gsize       *length,
                     GError     **error)
{
  gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
  gboolean retval;

  if (utf8_filename == NULL)
    return FALSE;

  retval = g_file_get_contents_utf8 (utf8_filename, contents, length, error);

  g_free (utf8_filename);

  return retval;
}
Example #17
0
static VALUE
rbglib_m_locale_to_utf8(G_GNUC_UNUSED VALUE self, VALUE str)
{
    GError *err = NULL;
    VALUE s = Qnil;
    gchar* ret;
    gsize written;

    StringValue(str);
    ret = g_locale_to_utf8(RSTRING_PTR(str), RSTRING_LEN(str),
                           NULL, &written, &err);

    if (err != NULL)
        RAISE_GERROR(err);
    s = rb_str_new(ret, written);
    g_free(ret);
    return s;
}
Example #18
0
static char *
convert_with_fallback (const char *str, const char *fallback)
{
	char *utf;

	utf = g_locale_to_utf8 (str, -1, 0, 0, 0);
	if (!utf)
	{
		/* this can happen if CHARSET envvar is set wrong */
		/* maybe it's already utf8 (breakage!) */
		if (!g_utf8_validate (str, -1, NULL))
			utf = g_strdup (fallback);
		else
			utf = g_strdup (str);
	}

	return utf;
}
Example #19
0
File: errors.c Project: Moeryn/bmc
void open_error(GtkWidget *file_selection, FILE *file, 
		const gchar * message_format, const gchar* path)
{
    if(file == NULL){
	GtkWidget *dialog;		
	dialog = gtk_message_dialog_new(GTK_WINDOW(file_selection),
					GTK_DIALOG_MODAL, 
					GTK_MESSAGE_ERROR, 
					GTK_BUTTONS_OK, 
					message_format, 
					g_locale_to_utf8(
							 path, -1, NULL, 
							 NULL, NULL));
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	return;
    }   
}
Example #20
0
gchar *
_gdk_win32_key_to_string (LONG lParam)
{
  char buf[100];
  gchar *keyname_utf8;

  if (GetKeyNameText (lParam, buf, sizeof (buf)) &&
      (keyname_utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL)) != NULL)
    {
      gchar *retval = static_printf ("%s", keyname_utf8);

      g_free (keyname_utf8);

      return retval;
    }

  return static_printf ("unk-%#lx", lParam);
}
Example #21
0
char *locale_to_utf8(const char *loc_str)
{
	if(NULL==loc_str)
		return NULL;
	gsize bytes_read;
	gsize bytes_written;
	GError *err=NULL;
	gchar *str=NULL;
	str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err);
	if(NULL==str){
		fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
		fprintf(stderr, "%s\n", err->message);
		g_error_free(err);
		exit(EXIT_FAILURE);
	}

	return str;
}
Example #22
0
gboolean CoreManager::io_input(GIOChannel *source, GIOCondition cond)
{
  if (io_input_timeout_conn.connected())
    io_input_timeout_conn.disconnect();

  termkey_advisereadable(tk);

  TermKeyKey key;
  TermKeyResult ret;
  while ((ret = termkey_getkey(tk, &key)) == TERMKEY_RES_KEY) {
    if (key.type == TERMKEY_TYPE_UNICODE && !utf8) {
      gsize bwritten;
      GError *err = NULL;
      char *utf8;

      // convert data from user charset to UTF-8
      if (!(utf8 = g_locale_to_utf8(key.utf8, -1, NULL, &bwritten, &err))) {
        if (err) {
          g_warning(_("Error converting input to UTF-8 (%s)."),
              err->message);
          g_error_free(err);
          err = NULL;
        }
        else
          g_warning(_("Error converting input to UTF-8."));
        continue;
      }

      memcpy(key.utf8, utf8, bwritten + 1);
      g_free(utf8);

      key.code.codepoint = g_utf8_get_char(key.utf8);
    }

    ProcessInput(key);
  }
  if (ret == TERMKEY_RES_AGAIN) {
    int wait = termkey_get_waittime(tk);
    io_input_timeout_conn = TimeoutOnceConnect(sigc::mem_fun(this,
          &CoreManager::io_input_timeout), wait);
  }

  return TRUE;
}
Example #23
0
gpointer
vsimple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, va_list ap)
{
  gchar             *vmessage;
  gchar             *message;
  queued_message_t *queued_message;
  GtkWidget        *win;
  GdkWindowState state = 0;

  /* Format the message. */
  vmessage = g_strdup_vprintf(msg_format, ap);

  /* convert character encoding from locale to UTF8 (using iconv) */
  message = g_locale_to_utf8(vmessage, -1, NULL, NULL, NULL);
  g_free(vmessage);

  if (top_level != NULL) {
    state = gdk_window_get_state(top_level->window);
  }

  /* If we don't yet have a main window or it's iconified, don't show the
     dialog. If showing up a dialog, while main window is iconified, program
     will become unresponsive! */
  if (top_level == NULL || state & GDK_WINDOW_STATE_ICONIFIED) {

    queued_message = g_malloc(sizeof (queued_message_t));
    queued_message->type = type;
    queued_message->btn_mask = btn_mask;
    queued_message->message = message;
    message_queue = g_slist_append(message_queue, queued_message);
    return NULL;
  }

  /*
   * Do we have any queued up messages?  If so, pop them up.
   */
  display_queued_messages();

  win = display_simple_dialog(type, btn_mask, message);

  g_free(message);

  return win;
}
Example #24
0
// all output ends up through here
void FPrintf(int flag, char *buf)
{
#if defined(USE_XML)
	xmlNodePtr      node;
	static qboolean bGotXML = qfalse;
	char            level[2];
#endif

	printf("%s", buf);

#if defined(USE_XML)
	// the following part is XML stuff only.. but maybe we don't want that message to go down the XML pipe?
	if(flag == SYS_NOXML)
		return;

	// output an XML file of the run
	// use the DOM interface to build a tree
	/*
	   <message level='flag'>
	   message string
	   .. various nodes to describe corresponding geometry ..
	   </message>
	 */
	if(!bGotXML)
	{
		// initialize
		doc = xmlNewDoc("1.0");
		doc->children = xmlNewDocRawNode(doc, NULL, "q3map_feedback", NULL);
		bGotXML = qtrue;
	}
	node = xmlNewNode(NULL, "message");
	{
		gchar          *utf8 = g_locale_to_utf8(buf, -1, NULL, NULL, NULL);

		xmlNodeSetContent(node, utf8);
		g_free(utf8);
	}
	level[0] = (int)'0' + flag;
	level[1] = 0;
	xmlSetProp(node, "level", (char *)&level);

	xml_SendNode(node);
#endif
}
static void
book_loaded_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	ESource *source = E_SOURCE (source_object);
	VCardImporter *gci = user_data;
	EClient *client = NULL;

	e_client_utils_open_new_finish (source, result, &client, NULL);

	if (client == NULL) {
		vcard_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);

	if (gci->encoding == VCARD_ENCODING_UTF16) {
		gchar *tmp;

		gunichar2 *contents_utf16 = (gunichar2 *) gci->contents;
		tmp = utf16_to_utf8 (contents_utf16);
		g_free (gci->contents);
		gci->contents = tmp;

	} else if (gci->encoding == VCARD_ENCODING_LOCALE) {
		gchar *tmp;
		tmp = g_locale_to_utf8 (gci->contents, -1, NULL, NULL, NULL);
		g_free (gci->contents);
		gci->contents = tmp;
	}

	gci->contactlist = eab_contact_list_from_string (gci->contents);
	g_free (gci->contents);
	gci->contents = NULL;
	gci->iterator = gci->contactlist;
	gci->total = g_slist_length (gci->contactlist);

	if (gci->iterator)
		gci->idle_id = g_idle_add (vcard_import_contacts, gci);
	else
		vcard_import_done (gci);
}
Example #26
0
gchar *utf8_convert(const gchar *in) {
    gsize rbytes, wbytes;
    gchar *out;
    GError *error = NULL;

    g_return_val_if_fail(in, NULL);

    out = g_locale_to_utf8(in, -1, &rbytes, &wbytes, &error);
    if (out == NULL && error != NULL) {
	if (g_utf8_validate(in, -1, NULL)) {
	    out = g_strdup(in);
	} else {
	    g_printerr("g_locale_to_utf8 failed: %s\n", error->message);
	    out = NULL;
	}
	g_error_free(error);
    }
    return out;
}
Example #27
0
sc_bool sc_helper_resolve_system_identifier(sc_memory_context const * ctx, const char *system_idtf, sc_addr *result)
{
    gchar *keynode_idtf = 0;
    gsize bytes_written = 0;

    keynode_idtf = g_locale_to_utf8(system_idtf, -1, 0, &bytes_written, 0);
    if (keynode_idtf == null_ptr)
    {
        g_warning("Error while trying to convert %s to utf-8", system_idtf);
        return SC_FALSE;
    }

    if (sc_helper_find_element_by_system_identifier(ctx, keynode_idtf, (sc_uint32)bytes_written, result) != SC_RESULT_OK)
        return SC_FALSE;

    g_free(keynode_idtf);

    return SC_TRUE;
}
Example #28
0
static gchar *get_wm_info(void)
{
    /* this code is taken from wmctrl utility, adapted
       Copyright (C) 2003, Tomas Styblo <*****@*****.**> */
    Display *disp;
    Window *sup_window = NULL;
    gchar *wm_name = NULL;

    if (!(disp = XOpenDisplay(NULL))) {
        fputs("Cannot open display.\n", stderr);
        return NULL;
    }

    if (!(sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
                    XA_WINDOW, "_NET_SUPPORTING_WM_CHECK", NULL))) {
        if (!(sup_window = (Window *)get_property(disp, DefaultRootWindow(disp),
                        XA_CARDINAL, "_WIN_SUPPORTING_WM_CHECK", NULL))) {
            fputs("Cannot get window manager info properties.\n"
                  "(_NET_SUPPORTING_WM_CHECK or _WIN_SUPPORTING_WM_CHECK)\n", stderr);
            return NULL;
        }
    }

    /* WM_NAME */
    if (!(wm_name = get_property(disp, *sup_window,
            XInternAtom(disp, "UTF8_STRING", False), "_NET_WM_NAME", NULL))) {
        if (!(wm_name = get_property(disp, *sup_window,
                XA_STRING, "_NET_WM_NAME", NULL))) {
            fputs("Cannot get name of the window manager (_NET_WM_NAME).\n", stderr);
        } else {
            gchar *_wm_name = wm_name;

            wm_name = g_locale_to_utf8(_wm_name, -1, NULL, NULL, NULL);
            if (wm_name)
                g_free(_wm_name);
            else
                /* Cannot convert string from locale charset to UTF-8. */
                wm_name = _wm_name;
        }
    }

    return wm_name;
}
Example #29
0
void context_output(int fd, const char *text, gint length)
{
	static int last_fd = -1;
	GtkTextIter end;
	gchar *utf8;

	gtk_text_buffer_get_end_iter(context, &end);

	if (last_fd == 3 && fd != 0)
		gtk_text_buffer_insert(context, &end, "\n", 1);

	if (fd != last_fd)
		last_fd = fd;

	if (length == -1)
		length = strlen(text);

	dc_chars += length;
	utf8 = g_locale_to_utf8(text, length, NULL, NULL, NULL);

	if (utf8)
	{
		gtk_text_buffer_insert_with_tags(context, &end, utf8, -1, fd_tags[fd], NULL);
		g_free(utf8);
	}
	else
		gtk_text_buffer_insert_with_tags(context, &end, text, length, fd_tags[fd], NULL);

	if (dc_chars > DC_LIMIT + (DC_DELTA / 2))
	{
		GtkTextIter start, delta;

		gtk_text_buffer_get_start_iter(context, &start);
		gtk_text_buffer_get_iter_at_offset(context, &delta, DC_DELTA);
		gtk_text_buffer_delete(context, &start, &delta);
		gtk_text_buffer_get_end_iter(context, &end);
		dc_chars = gtk_text_buffer_get_char_count(context);
	}

	gtk_text_buffer_place_cursor(context, &end);
	gtk_text_view_scroll_mark_onscreen(debug_context, gtk_text_buffer_get_insert(context));
}
Example #30
0
gchar* get_time (const gchar* format)
{
	gchar *out = NULL;
	gchar *out_utf8 = NULL;
	time_t clock;
	struct tm *now;
	size_t out_length = 0;
	gchar *locale_format;

	if (strlen (format) == 0)
		return g_strdup (" ");

	locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);

	if (! locale_format)
		return g_strdup (" ");

	clock = time (NULL);
	now = localtime (&clock);

	do
	{
		out_length += 255;
		out = g_realloc (out, out_length);
	}
	while (strftime (out, out_length, locale_format, now) == 0);

	g_free (locale_format);

	if (g_utf8_validate (out, -1, NULL))
		out_utf8 = out;
	else
	{
		out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL);
		g_free (out);

		if (! out_utf8)
			out_utf8 = g_strdup (" ");
	}

	return out_utf8;
}