Changeset c111da2 in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2025-10-09T15:44:52Z (2 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
cfd04c4
Parents:
1a96db9
Message:

Create non-zero size file in Navigator, new newfile utility.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/capa.c

    r1a96db9 rc111da2  
    11/*
    2  * Copyright (c) 2015 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    233233}
    234234
     235errno_t capa_format_buf(capa_spec_t *capa, char *buf, size_t bufsize)
     236{
     237        errno_t rc;
     238        const char *sunit;
     239        uint64_t ipart;
     240        uint64_t fpart;
     241        uint64_t div;
     242
     243        sunit = NULL;
     244
     245        assert(capa->cunit < CU_LIMIT);
     246
     247        rc = ipow10_u64(capa->dp, &div);
     248        if (rc != EOK)
     249                return rc;
     250
     251        ipart = capa->m / div;
     252        fpart = capa->m % div;
     253
     254        sunit = cu_str[capa->cunit];
     255        if (capa->dp > 0) {
     256                snprintf(buf, bufsize, "%" PRIu64 ".%0*" PRIu64 " %s", ipart,
     257                    (int)capa->dp, fpart, sunit);
     258        } else {
     259                snprintf(buf, bufsize, "%" PRIu64 " %s", ipart, sunit);
     260        }
     261
     262        return EOK;
     263}
     264
     265errno_t capa_blocks_format(uint64_t nblocks, size_t block_size,
     266    char **rptr)
     267{
     268        capa_spec_t capa;
     269
     270        capa_from_blocks(nblocks, block_size, &capa);
     271        capa_simplify(&capa);
     272        return capa_format(&capa, rptr);
     273}
     274
     275void capa_blocks_format_buf(uint64_t nblocks, size_t block_size,
     276    char *buf, size_t bsize)
     277{
     278        capa_spec_t capa;
     279        errno_t rc;
     280
     281        capa_from_blocks(nblocks, block_size, &capa);
     282        capa_simplify(&capa);
     283
     284        /* Should not get range error because of nblocks * block_size limits */
     285        rc = capa_format_buf(&capa, buf, bsize);
     286        assert(rc == EOK);
     287        (void)rc;
     288}
     289
    235290static errno_t capa_digit_val(char c, int *val)
    236291{
Note: See TracChangeset for help on using the changeset viewer.