static void vpr(int code, const char *fmt, va_list ap) { char path[MAXPATHLEN+1]; char siz[5], ino[5]; int64_t s, i; s = df(); i = inodes(); if (errno == ENOSPC && (flags & MNT_SOFTDEP) && (flags & MNT_QUOTA) == 0 && s > 100 && i > 100) { if (getcwd(path, sizeof(path)) == NULL) err(1, "getcwd()"); humanize_number(siz, sizeof(siz), s, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); humanize_number(ino, sizeof(ino), i, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); printf("A syscall has failed with ENOSPC even though free disk " "space for %s is reported as %s and %s inodes.\n", path, siz, ino); } fprintf(stderr, "%s: ", getprogname()); if (fmt != NULL) { vfprintf(stderr, fmt, ap); fprintf(stderr, ": "); } fprintf(stderr, "%s\n", strerror(code)); }
/* * swapmode is based on a program called swapinfo written * by Kevin Lahey <*****@*****.**>. */ void swapmode(void) { struct kvm_swap kswap[16]; int i; int n; const char *header; int hlen; pagesize = getpagesize(); n = kvm_getswapinfo( kd, kswap, sizeof(kswap)/sizeof(kswap[0]), ((swapflag > 1) ? SWIF_DUMP_TREE : 0) | SWIF_DEV_PREFIX ); #define CONVERT(v) ((long)((quad_t)(v) * pagesize / blocksize)) #define CONVERTB(v) ((long)((quad_t)(v) * pagesize)) if (humanflag) { hlen = 9; header = " Blocks"; } else { header = getbsize(&hlen, &blocksize); } if (totalflag == 0) { printf("%-15s %*s %8s %8s %8s %s\n", "Device", hlen, header, "Used", "Avail", "Capacity", "Type"); for (i = 0; i < n; ++i) { Output(kswap[i].ksw_devname, hlen, &kswap[i], 1); } } if (totalflag) { if (humanflag) { char buf1[6]; char buf2[6]; humanize_number(buf1, sizeof(buf1), CONVERTB(kswap[n].ksw_used), "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); humanize_number(buf2, sizeof(buf2), CONVERTB(kswap[n].ksw_total), "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); printf("%s/%s swap space\n", buf1, buf2); } else { blocksize = 1024 * 1024; printf("%ldM/%ldM swap space\n", CONVERT(kswap[n].ksw_used), CONVERT(kswap[n].ksw_total)); } } else if (n > 1) { Output("Total", hlen, &kswap[n], 0); } }
static void update_sharedlibs(struct globalstat *gs, const libtop_tsamp_t *tsamp) { char code[6]; char data[6]; char linkedit[6]; if((-1 == humanize_number(code, sizeof(code), tsamp->fw_code, "", HN_AUTOSCALE, GLOBALSTAT_HN_FORMAT)) || (-1 == humanize_number(data, sizeof(data), tsamp->fw_data, "", HN_AUTOSCALE, GLOBALSTAT_HN_FORMAT)) || (-1 == humanize_number(linkedit, sizeof(linkedit), tsamp->fw_linkedit, "", HN_AUTOSCALE, GLOBALSTAT_HN_FORMAT))) { reset_globalstat(gs); return; } gs->length = snprintf(gs->data, sizeof(gs->data), "SharedLibs: " "%s resident, " "%s data, " "%s linkedit.", code, data, linkedit); if(gs->length < 0) { reset_globalstat(gs); return; } update_max(gs); }
void print_pid(char *obuf, int idx) { int i; char buf[8], xbuf[80]; const char *die = ""; if (sortedprocs[idx]->node == NULL) return; sprintf(obuf, "%*s", maxnodelen, sortedprocs[idx]->node->name); sprintf(xbuf, " %6d", sortedprocs[idx]->pid); strcat(obuf, xbuf); sprintf(xbuf, " %8s", sortedprocs[idx]->username); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortedprocs[idx]->size, die, HN_AUTOSCALE, HN_NOSPACE|HN_DECIMAL); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortedprocs[idx]->res, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); sprintf(xbuf, " %5.2f%%", sortedprocs[idx]->cpu); strcat(obuf, xbuf); sprintf(xbuf, " %-30s", sortedprocs[idx]->command); strcat(obuf, xbuf); }
void print_nodedata(char *obuf, int idx) { int i; float f; char buf[8], xbuf[80]; sprintf(obuf, "%*s %6d %6.2f %6.2f %6.2f", maxnodelen, sortnode[idx].node->name, sortnode[idx].procs, sortnode[idx].load1, sortnode[idx].load5, sortnode[idx].load15); i = humanize_number(buf, 6, sortnode[idx].actmem, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortnode[idx].inactmem, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortnode[idx].filemem, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortnode[idx].freemem, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); i = humanize_number(buf, 6, sortnode[idx].swapfree, "", HN_AUTOSCALE, HN_NOSPACE); if (i == -1) sprintf(xbuf, " UNK"); else sprintf(xbuf, " %6s", buf); strcat(obuf, xbuf); f = 1.0 - ((float)sortnode[idx].swapfree / (float)sortnode[idx].swap); f *= 100.0; sprintf(xbuf, " %5.2f%%", f); strcat(obuf, xbuf); }
int exec_stats(int argc, char **argv) { struct pkgdb *db = NULL; int64_t flatsize = 0; char size[7]; int retcode = EX_OK; int ch; while ((ch = getopt(argc, argv, "q")) != -1) { switch (ch) { case 'q': quiet = true; break; default: usage_stats(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc > 2) { usage_stats(); return (EX_USAGE); } if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) { return (EX_IOERR); } printf("Local package database:\n"); printf("\tInstalled packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_LOCAL_COUNT)); flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE); humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0); printf("\tDisk space occupied: %s\n\n", size); printf("Remote package database(s):\n"); printf("\tNumber of repositories: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_REPOS)); printf("\tPackages available: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_COUNT)); printf("\tUnique packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_UNIQUE)); flatsize = pkgdb_stats(db, PKG_STATS_REMOTE_SIZE); humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0); printf("\tTotal size of packages: %s\n", size); pkgdb_close(db); return (retcode); }
static void print_size(off_t size, int size_max) { char size_buff[SIZE_BUFF_SIZE]; if (f_readable) { if (humanize_number(size_buff, SIZE_BUFF_SIZE, (int64_t)size, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE) == -1) { /* transformation failed, uses '?' to represent */ size_buff[0] = '?'; size_buff[1] = '\0'; return_val = EXIT_FAILURE; } printf("%*s ", size_max, size_buff); } else if (f_kb) { printf("%*"PRIuMAX" ", size_max, (uintmax_t)size / 1024); } else { printf("%*"PRIuMAX" ", size_max, (uintmax_t)size); } }
static void print_block(int64_t size, int block_max) { char block_buff[BLOCK_BUFF_SIZE]; if (f_readable) { if (humanize_number(block_buff, BLOCK_BUFF_SIZE, size / blksize, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE) == -1) { /* transformation failed, uses '?' to represent */ block_buff[0] = '?'; block_buff[1] = '\0'; return_val = EXIT_FAILURE; } printf("%*s ", block_max, block_buff); } else if (f_kb) { printf("%*"PRIuMAX" ", block_max, (uintmax_t)(size / 1024)); } else { printf("%*"PRIuMAX" ", block_max, (uintmax_t)(size / blksize)); } }
static void format_stripe(char *buf, size_t buflen, uint8_t stripe) { humanize_number(buf, buflen, (1 << stripe) * 512, "", HN_AUTOSCALE, HN_B | HN_NOSPACE); }
static void ptable_print(void *arg, const char *pname, const struct ptable_entry *part) { struct ptable *table; struct disk *dp, bsd; char line[80], size[6]; dp = (struct disk *)arg; sprintf(line, " %s%s: %s", dp->file ? "disk0": dp->name, pname, parttype2str(part->type)); humanize_number(size, sizeof(size), (part->end - part->start + 1) * dp->sectorsize, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); printf("%-*s%s\n", PWIDTH, line, size); if (part->type == PART_FREEBSD) { sprintf(line, "%s%s", dp->file ? "disk0": dp->name, pname); bsd.name = line; bsd.fd = dp->fd; bsd.file = 0; /* to use dp->name in the next sprintf */ bsd.offset = dp->offset + part->start; bsd.sectorsize = dp->sectorsize; bsd.mediasize = (part->end - part->start + 1) * dp->sectorsize; table = ptable_open(&bsd, bsd.mediasize / bsd.sectorsize, bsd.sectorsize, diskread); if (table == NULL) return; ptable_iterate(table, &bsd, ptable_print); ptable_close(table); } }
/* * print [inode] [size] name * return # of characters printed, no trailing characters. */ static int printaname(FTSENT *p, int inodefield, int sizefield) { struct stat *sp; int chcnt; char szbuf[5]; sp = p->fts_statp; chcnt = 0; if (f_inode) chcnt += printf("%*"PRIu64" ", inodefield, sp->st_ino); if (f_size) { if (f_humanize) { if ((humanize_number(szbuf, sizeof(szbuf), sp->st_size, "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1) err(1, "humanize_number"); chcnt += printf("%*s ", sizefield, szbuf); } else { chcnt += printf(f_commas ? "%'*llu " : "%*llu ", sizefield, (unsigned long long) howmany(sp->st_blocks, blocksize)); } } if (f_octal || f_octal_escape) chcnt += safe_printpath(p); else if (f_nonprint) chcnt += printescapedpath(p); else chcnt += printpath(p); if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) chcnt += printtype(sp->st_mode); return (chcnt); }
static char * humanize_usage_amount(char *usage) { int64_t num; const char *resource, *amount; char *copy, *humanized, buf[6]; copy = strdup(usage); if (copy == NULL) err(1, "strdup"); resource = strsep(©, "="); amount = copy; assert(resource != NULL); assert(amount != NULL); if (str2int64(amount, &num) != 0 || humanize_number(buf, sizeof(buf), num, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE) == -1) { free(copy); return (usage); } asprintf(&humanized, "%s=%s", resource, buf); if (humanized == NULL) err(1, "asprintf"); return (humanized); }
static void printfile(int fileid, int verbose, int humanized) { struct kld_file_stat stat; int modid; char buf[5]; stat.version = sizeof(struct kld_file_stat); if (kldstat(fileid, &stat) < 0) { err(1, "can't stat file id %d", fileid); } else { if (humanized) { humanize_number(buf, sizeof(buf), stat.size, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE); printf("%2d %4d %p %5s %s", stat.id, stat.refs, stat.address, buf, stat.name); } else { printf("%2d %4d %p %8zx %s", stat.id, stat.refs, stat.address, stat.size, stat.name); } } if (verbose) { printf(" (%s)\n", stat.pathname); printf("\tContains modules:\n"); printf("\t\tId Name\n"); for (modid = kldfirstmod(fileid); modid > 0; modid = modfnext(modid)) printmod(modid); } else printf("\n"); }
/* Find a good place to play. */ static char * find_play_pen(char *pen, off_t sz) { char *cp; struct stat sb; char humbuf[6]; if (pen[0] && isdir(dirname(pen)) == TRUE && (min_free(dirname(pen)) >= sz)) return pen; else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) sprintf(pen, "%s/instmp.XXXXXX", cp); else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) sprintf(pen, "%s/instmp.XXXXXX", cp); else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) strcpy(pen, "/var/tmp/instmp.XXXXXX"); else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz) strcpy(pen, "/tmp/instmp.XXXXXX"); else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz) strcpy(pen, "/usr/tmp/instmp.XXXXXX"); else { cleanup(0); humanize_number(humbuf, sizeof humbuf, sz, "", HN_AUTOSCALE, HN_NOSPACE); errx(2, "%s: can't find enough temporary space to extract the files, please set your\n" "PKG_TMPDIR environment variable to a location with at least %s bytes\n" "free", __func__, humbuf); return NULL; } return pen; }
static void format_stripe(char *buf, size_t buflen, U32 stripe) { humanize_number(buf, buflen, stripe * 512, "", HN_AUTOSCALE, HN_B | HN_NOSPACE); }
static void Output(const char *name, int hlen, struct kvm_swap *kswap, int flags) { char buf1[32]; char buf2[32]; char buf3[32]; if (humanflag) { humanize_number(buf1, 6, CONVERTB(kswap->ksw_total), "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); humanize_number(buf2, 6, CONVERTB(kswap->ksw_used), "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); humanize_number(buf3, 6, CONVERTB(kswap->ksw_total - kswap->ksw_used), "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); } else { snprintf(buf1, sizeof(buf1), "%*ld", hlen, CONVERT(kswap->ksw_total)); snprintf(buf2, sizeof(buf2), "%8ld", CONVERT(kswap->ksw_used)); snprintf(buf3, sizeof(buf2), "%8ld", CONVERT(kswap->ksw_total - kswap->ksw_used)); } printf("%-15s %*s ", name, hlen, buf1); printf("%8s %8s %5.0f%%", buf2, buf3, (double)kswap->ksw_used * 100.0 / (double)kswap->ksw_total); if (flags) { printf(" %s", ((kswap->ksw_flags & SW_SEQUENTIAL) ? "Sequential" : "Interleaved")); } printf("\n"); }
static void flash_attach(device_t parent, device_t self, void *aux) { char nbuf[32]; struct flash_softc *sc = device_private(self); struct arbus_attach_args *aa = aux; int i; bus_space_tag_t iot = aa->aa_bst; bus_space_handle_t ioh; uint16_t venid, devid; if (bus_space_map(iot, aa->aa_addr, aa->aa_size, 0, &ioh)) { printf(": can't map i/o space\n"); return; } sc->sc_iot = iot; sc->sc_ioh = ioh; sc->sc_status = 0; /* issue JEDEC query */ bus_space_write_2(aa->aa_bst, ioh, (0x5555 << 1), 0xAAAA); bus_space_write_2(aa->aa_bst, ioh, (0x2AAA << 1), 0x5555); bus_space_write_2(aa->aa_bst, ioh, (0x5555 << 1), 0x9090); delay(100); venid = bus_space_read_2(aa->aa_bst, ioh, 0); devid = bus_space_read_2(aa->aa_bst, ioh, 2); /* issue software exit */ bus_space_write_2(aa->aa_bst, ioh, 0x0, 0xF0F0); for (i = 0; flash_ids[i].name != NULL; i++) { if ((venid == flash_ids[i].vendor_id) && (devid == flash_ids[i].device_id)) { break; } } KASSERT(flash_ids[i].name != NULL); printf(": %s", flash_ids[i].name); if (humanize_number(nbuf, sizeof(nbuf), flash_ids[i].flash_size, "B", 1024) > 0) printf(" (%s)", nbuf); /* * determine size of the largest block */ sc->sc_size = flash_ids[i].flash_size; sc->sc_sector_size = flash_ids[i].sector_size; if ((sc->sc_buf = malloc(sc->sc_sector_size, M_DEVBUF, M_NOWAIT)) == NULL) { printf(": can't alloc buffer space\n"); return; } printf("\n"); }
static void sizetobuf( char *buf, size_t bufsize, int hflag, long long val, int hlen, long blocksize ) { char tmp[16]; if ( hflag == 'H' ) { humanize_number( tmp, 5, (int64_t) val, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL ); snprintf( buf, bufsize, "%*s", hlen, tmp ); } else snprintf( buf, bufsize, "%*lld", hlen, val / blocksize ); }
/* * Small wrapper for NetBSD's humanize_number(3) with some * defaults set that we care about. */ int xbps_humanize_number(char *buf, int64_t bytes) { assert(buf != NULL); return humanize_number(buf, 7, bytes, "B", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE); }
/* * Make a temporary directory to play in and chdir() to it, returning * pathname of previous working directory. */ const char * make_playpen(char *pen, off_t sz) { char humbuf1[6], humbuf2[6]; char cwd[FILENAME_MAX]; if (!find_play_pen(pen, sz)) return NULL; if (!mkdtemp(pen)) { cleanup(0); errx(2, "%s: can't mktemp '%s'", __func__, pen); } if (Verbose) { if (sz) { humanize_number(humbuf1, sizeof humbuf1, sz, "", HN_AUTOSCALE, HN_NOSPACE); humanize_number(humbuf2, sizeof humbuf2, min_free(pen), "", HN_AUTOSCALE, HN_NOSPACE); fprintf(stderr, "Requested space: %s bytes, free space: %s bytes in %s\n", humbuf1, humbuf2, pen); } } if (min_free(pen) < sz) { rmdir(pen); cleanup(0); errx(2, "%s: not enough free space to create '%s'.\n" "Please set your PKG_TMPDIR environment variable to a location\n" "with more space and\ntry the command again", __func__, pen); } if (!getcwd(cwd, FILENAME_MAX)) { upchuck("getcwd"); return NULL; } if (chdir(pen) == FAIL) { cleanup(0); errx(2, "%s: can't chdir to '%s'", __func__, pen); } strcpy(PenLocation, pen); return pushPen(cwd); }
static const char * humanize_rlimit(int indx, rlim_t limit) { static char buf[14]; int scale; if (limit == RLIM_INFINITY) return ("infinity "); scale = humanize_number(buf, sizeof(buf) - 1, (int64_t)limit, rlimit_param[indx].suffix, HN_AUTOSCALE | HN_GETSCALE, HN_DECIMAL); (void)humanize_number(buf, sizeof(buf) - 1, (int64_t)limit, rlimit_param[indx].suffix, HN_AUTOSCALE, HN_DECIMAL); /* Pad with one space if there is no suffix prefix. */ if (scale == 0) sprintf(buf + strlen(buf), " "); return (buf); }
void showdf(void) { int i, j, skip; char s[MNAMELEN]; char s2[MNAMELEN]; float pct; int64_t used, bsize, bavail, availblks; int y; y=2; /* at what line to start displaying */ for (i=0; i<nfss; i++) { skip = 0; for(j=0; nodisplay[j] != NULL; j++) { if (strcmp(nodisplay[j], fss[i].f_fstypename) == 0) { skip=1; break; } } if (displayall || !skip) { wmove(wnd, y, 0); wclrtoeol(wnd); snprintf(s, sizeof(s), "%s", fss[i].f_mntonname); mvwaddstr(wnd, y, 0, s); used = fss[i].f_blocks - fss[i].f_bfree; bavail = fss[i].f_bavail; availblks = bavail + used; bsize = fss[i].f_frsize; if (availblks == 0) { pct = 1.0; /* full pseudo-disk */ } else { pct = (1.0 * used) / availblks; } #define FREELEN 7 humanize_number(s2, FREELEN, bavail*bsize, " |", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); snprintf(s, sizeof(s), "%*s", FREELEN, s2); mvwaddstr(wnd, y, 25-FREELEN, s); #undef FREELEN mvwhline(wnd, y, 25, 'X', (int)(51*pct)); y++; } } wmove(wnd, y, 0); wclrtobot(wnd); }
static void prthumanval(int64_t bytes, const char *pad) { char buf[6]; (void)humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); (void)printf("%s %6s", pad, buf); }
static void prthuman(u_int64_t val, int size) { char buf[10]; int flags; if (size < 5 || size > 9) errx(1, "doofus"); flags = HN_B | HN_NOSPACE | HN_DECIMAL; humanize_number(buf, size, val, "", HN_AUTOSCALE, flags); printf("%*s", size, buf); }
static void prthumanval(int len, u_int64_t bytes) { char buf[len + 1]; /* * Limit the width to 5 bytes as that is what users expect. */ humanize_number(buf, MIN(sizeof(buf), 5), bytes, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); (void)printf(" %*s", len, buf); }
char * fmthumanvalinos(int64_t inos) { static char numbuf[20]; if (hflag) { humanize_number(numbuf, inos < 0 ? 7 : 6, inos, "", HN_AUTOSCALE, HN_NOSPACE | HN_DIVISOR_1000); return (numbuf); } snprintf(numbuf, sizeof(numbuf), "%ju", (uintmax_t)inos); return(numbuf); }
/* * Print an inode count in "human-readable" format. */ static void prthumanvalinode(int64_t bytes) { char buf[6]; int flags; flags = HN_NOSPACE | HN_DECIMAL | HN_DIVISOR_1000; humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, flags); (void)printf(" %5s", buf); }
char * fmthumanvalblks(int64_t blocks) { static char numbuf[20]; if (hflag) { humanize_number(numbuf, blocks < 0 ? 7 : 6, dbtob(blocks), "", HN_AUTOSCALE, HN_NOSPACE); return (numbuf); } snprintf(numbuf, sizeof(numbuf), "%juk", (uintmax_t)dbtokb(blocks)); return(numbuf); }
int prthumanval(uint64_t bytes) { char buf[6]; int flags; //flags = HN_NOSPACE | HN_DECIMAL | HN_DIVISOR_1000; //flags = HN_NOSPACE | HN_DECIMAL; flags = HN_NOSPACE; humanize_number(buf, sizeof(buf) - 1, bytes, "", HN_AUTOSCALE, flags); (void)printf("%s", buf); return 0; }
const char * capacity_to_string(long capacity) { static char string[6]; if (capacity < 0) strlcpy(string, "*", 2); else humanize_number(string, sizeof(string), (int64_t)capacity * 1024 * 1024, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); return(string); }