| 873 | } |
| 874 | |
| 875 | void humanise_bytes(off_t bytes, char **value, const char **unit, |
| 876 | unsigned flags) |
| 877 | { |
| 878 | int humanise_rate = flags & HUMANISE_RATE; |
| 879 | |
| 880 | if (bytes > 1 << 30) { |
| 881 | *value = xstrfmt(_("%u.%2.2u"), (unsigned)(bytes >> 30), |
| 882 | (unsigned)(bytes & ((1 << 30) - 1)) / 10737419); |
| 883 | /* TRANSLATORS: IEC 80000-13:2008 gibibyte/second and gibibyte */ |
| 884 | *unit = humanise_rate ? _("GiB/s") : _("GiB"); |
| 885 | } else if (bytes > 1 << 20) { |
| 886 | unsigned x = bytes + 5243; /* for rounding */ |
| 887 | *value = xstrfmt(_("%u.%2.2u"), x >> 20, |
| 888 | ((x & ((1 << 20) - 1)) * 100) >> 20); |
| 889 | /* TRANSLATORS: IEC 80000-13:2008 mebibyte/second and mebibyte */ |
| 890 | *unit = humanise_rate ? _("MiB/s") : _("MiB"); |
| 891 | } else if (bytes > 1 << 10) { |
| 892 | unsigned x = bytes + 5; /* for rounding */ |
| 893 | *value = xstrfmt(_("%u.%2.2u"), x >> 10, |
| 894 | ((x & ((1 << 10) - 1)) * 100) >> 10); |
| 895 | /* TRANSLATORS: IEC 80000-13:2008 kibibyte/second and kibibyte */ |
| 896 | *unit = humanise_rate ? _("KiB/s") : _("KiB"); |
| 897 | } else { |
| 898 | *value = xstrfmt("%u", (unsigned)bytes); |
| 899 | if (flags & HUMANISE_COMPACT) |
| 900 | /* TRANSLATORS: IEC 80000-13:2008 byte/second and byte */ |
| 901 | *unit = humanise_rate ? _("B/s") : _("B"); |
| 902 | else |
| 903 | *unit = humanise_rate ? |
| 904 | /* TRANSLATORS: IEC 80000-13:2008 byte/second */ |
| 905 | Q_("byte/s", "bytes/s", bytes) : |
| 906 | /* TRANSLATORS: IEC 80000-13:2008 byte */ |
| 907 | Q_("byte", "bytes", bytes); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | static void strbuf_humanise(struct strbuf *buf, off_t bytes, unsigned flags) |
| 912 | { |
no test coverage detected