31
31
#include <stdlib.h>
32
33
#include "fm-utils.h"
33
34
#include "fm-file-info-job.h"
35
#define BI_KiB ((gdouble)1024.0)
36
#define BI_MiB ((gdouble)1024.0 * 1024.0)
37
#define BI_GiB ((gdouble)1024.0 * 1024.0 * 1024.0)
38
#define BI_TiB ((gdouble)1024.0 * 1024.0 * 1024.0 * 1024.0)
36
#define BI_KiB ((gdouble)1024.0)
37
#define BI_MiB ((gdouble)1024.0 * 1024.0)
38
#define BI_GiB ((gdouble)1024.0 * 1024.0 * 1024.0)
39
#define BI_TiB ((gdouble)1024.0 * 1024.0 * 1024.0 * 1024.0)
40
#define SI_KB ((gdouble)1000.0)
41
#define SI_MB ((gdouble)1000.0 * 1000.0)
42
#define SI_GB ((gdouble)1000.0 * 1000.0 * 1000.0)
43
#define SI_TB ((gdouble)1000.0 * 1000.0 * 1000.0 * 1000.0)
41
#define SI_KB ((gdouble)1000.0)
42
#define SI_MB ((gdouble)1000.0 * 1000.0)
43
#define SI_GB ((gdouble)1000.0 * 1000.0 * 1000.0)
44
#define SI_TB ((gdouble)1000.0 * 1000.0 * 1000.0 * 1000.0)
45
46
char* fm_file_size_to_str( char* buf, goffset size, gboolean si_prefix )
50
if( si_prefix ) /* 1000 based SI units */
52
if(size < (goffset)SI_KB)
54
sprintf( buf, ngettext("%u byte", "%u bytes", (guint)size), (guint)size);
79
else /* 1024-based binary prefix */
81
if(size < (goffset)BI_KiB)
83
sprintf( buf, ngettext("%u byte", "%u bytes", (guint)size), (guint)size);
51
if( si_prefix ) /* 1000 based SI units */
53
if(size < (goffset)SI_KB)
55
sprintf( buf, ngettext("%u byte", "%u bytes", (guint)size), (guint)size);
80
else /* 1024-based binary prefix */
82
if(size < (goffset)BI_KiB)
84
sprintf( buf, ngettext("%u byte", "%u bytes", (guint)size), (guint)size);
108
109
sprintf( buf, "%.1f %s", val, unit );
112
113
gboolean fm_key_file_get_int(GKeyFile* kf, const char* grp, const char* key, int* val)
217
char* fm_str_replace(char* str, char* old, char* new)
220
int len = strlen(str);
222
GString* buf = g_string_sized_new(len);
223
while(found = strstr(str, old))
225
g_string_append_len(buf, str, (found - str));
226
g_string_append(buf, new);
230
g_string_append_c(buf, *str);
231
return g_string_free(buf, FALSE);