1 /* nbd client library in userspace
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef LIBNBD_HUMAN_SIZE_H
20 #define LIBNBD_HUMAN_SIZE_H
25 /* If you allocate a buffer of at least this length in bytes and pass
26 * it as the first parameter to human_size, then it will not overrun.
28 #define HUMAN_SIZE_LONGEST 64
30 /* Convert bytes to a human-readable string.
32 * This is roughly the opposite of nbdkit_parse_size. It will convert
33 * multiples of powers of 1024 to the appropriate human size with the
34 * right extension like 'M' or 'G'. Anything that cannot be converted
35 * is returned as bytes. The *human flag is set to true if the output
36 * was abbreviated to a human-readable size, or false if it is just
39 * If buf == NULL, a buffer is allocated and returned. In this case
40 * the returned buffer must be freed.
42 * buf may also be allocated by the caller, in which case it must be
43 * at least HUMAN_SIZE_LONGEST bytes.
45 * On error the function returns an error and sets errno.
47 extern char *human_size (char *buf
, uint64_t bytes
, bool *human
);
49 #endif /* LIBNBD_HUMAN_SIZE_H */