mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-30 05:43:28 +02:00
Move g_format_file_size_for_display from gio to glib
2007-11-27 Alexander Larsson <alexl@redhat.com> * gio/gfileinfo.[ch]: * glib/gfileutils.[ch]: Move g_format_file_size_for_display from gio to glib svn path=/trunk/; revision=5954
This commit is contained in:
committed by
Alexander Larsson
parent
5247f12f36
commit
68c74ba68f
@@ -1800,6 +1800,51 @@ g_build_filename (const gchar *first_element,
|
||||
return str;
|
||||
}
|
||||
|
||||
#define KILOBYTE_FACTOR 1024.0
|
||||
#define MEGABYTE_FACTOR (1024.0 * 1024.0)
|
||||
#define GIGABYTE_FACTOR (1024.0 * 1024.0 * 1024.0)
|
||||
|
||||
/**
|
||||
* g_format_file_size_for_display:
|
||||
* @size: a file size.
|
||||
*
|
||||
* Formats a file size into a human readable string. Sizes are rounded
|
||||
* to the nearest metric prefix and are displayed rounded to the nearest
|
||||
* tenth. E.g. the file size 3292528 bytes will be converted into the string
|
||||
* "3.1 MB".
|
||||
*
|
||||
* Returns: a formatted string containing a human readable file size.
|
||||
*
|
||||
* Since: 2.16
|
||||
**/
|
||||
char *
|
||||
g_format_file_size_for_display (goffset size)
|
||||
{
|
||||
if (size < (goffset) KILOBYTE_FACTOR)
|
||||
return g_strdup_printf (dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size), (guint) size);
|
||||
else
|
||||
{
|
||||
gdouble displayed_size;
|
||||
|
||||
if (size < (goffset) MEGABYTE_FACTOR)
|
||||
{
|
||||
displayed_size = (gdouble) size / KILOBYTE_FACTOR;
|
||||
return g_strdup_printf (_("%.1f KB"), displayed_size);
|
||||
}
|
||||
else if (size < (goffset) GIGABYTE_FACTOR)
|
||||
{
|
||||
displayed_size = (gdouble) size / MEGABYTE_FACTOR;
|
||||
return g_strdup_printf (_("%.1f MB"), displayed_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
displayed_size = (gdouble) size / GIGABYTE_FACTOR;
|
||||
return g_strdup_printf (_("%.1f GB"), displayed_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_file_read_link:
|
||||
* @filename: the symbolic link
|
||||
|
Reference in New Issue
Block a user