Function

GLibfilename_display_name

since: 2.6

Declaration

gchar*
g_filename_display_name (
  const gchar* filename
)

Description

Converts a filename into a valid UTF-8 string. The conversion is not necessarily reversible, so you should keep the original around and use the return value of this function only for display purposes. Unlike g_filename_to_utf8(), the result is guaranteed to be non-NULL even if the filename actually isn’t in the GLib file name encoding.

If GLib cannot make sense of the encoding of filename, as a last resort it replaces unknown characters with U+FFFD, the Unicode replacement character. You can search the result for the UTF-8 encoding of this character (which is “\357\277\275” in octal notation) to find out if filename was in an invalid encoding.

If you know the whole pathname of the file you should use g_filename_display_basename(), since that allows location-based translation of filenames.

Available since: 2.6

Parameters

filename

Type: const gchar*

A pathname hopefully in the GLib file name encoding.

The data is owned by the caller of the function.
The value is a file system path, using the OS encoding.

Return value

Type: gchar*

A newly allocated string containing a rendition of the filename in valid UTF-8

The caller of the function takes ownership of the data, and is responsible for freeing it.
The value is a NUL terminated UTF-8 string.