Changeset 08e103d4 in mainline for kernel


Ignore:
Timestamp:
2019-02-05T18:26:05Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
1d2f85e
Parents:
d066259
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-05 16:16:55)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-05 18:26:05)
Message:

Use clearer naming for string length functions

This and the following commit change the names of functions, as well as
their documentation, to use unambiguous terms "bytes" and "code points"
instead of ambiguous terms "size", "length", and "characters".

Location:
kernel
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/amd64.c

    rd066259 r08e103d4  
    185185
    186186        sysinfo_set_item_data("platform", NULL, (void *) platform,
    187             str_size(platform));
     187            str_bytes(platform));
    188188
    189189#ifdef CONFIG_PC_KBD
  • kernel/arch/arm32/src/arm32.c

    rd066259 r08e103d4  
    113113
    114114        sysinfo_set_item_data("platform", NULL, (void *) platform,
    115             str_size(platform));
     115            str_bytes(platform));
    116116}
    117117
  • kernel/arch/ia32/src/ia32.c

    rd066259 r08e103d4  
    170170
    171171        sysinfo_set_item_data("platform", NULL, (void *) platform,
    172             str_size(platform));
     172            str_bytes(platform));
    173173
    174174#ifdef CONFIG_PC_KBD
  • kernel/arch/ia64/src/ia64.c

    rd066259 r08e103d4  
    156156#endif
    157157        sysinfo_set_item_data("platform", NULL, (void *) platform,
    158             str_size(platform));
     158            str_bytes(platform));
    159159
    160160#ifdef MACHINE_ski
  • kernel/arch/mips32/src/mips32.c

    rd066259 r08e103d4  
    155155        sysinfo_set_item_data("platform", NULL,
    156156            (void *) machine_get_platform_name(),
    157             str_size(machine_get_platform_name()));
     157            str_bytes(machine_get_platform_name()));
    158158
    159159        machine_input_init();
  • kernel/arch/ppc32/src/ppc32.c

    rd066259 r08e103d4  
    281281
    282282        sysinfo_set_item_data("platform", NULL, (void *) platform,
    283             str_size(platform));
     283            str_bytes(platform));
    284284
    285285        ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
  • kernel/arch/sparc64/src/sun4u/sparc64.c

    rd066259 r08e103d4  
    127127
    128128        sysinfo_set_item_data("platform", NULL, (void *) platform,
    129             str_size(platform));
     129            str_bytes(platform));
    130130
    131131        standalone_sparc64_console_init();
  • kernel/arch/sparc64/src/sun4v/sparc64.c

    rd066259 r08e103d4  
    125125
    126126        sysinfo_set_item_data("platform", NULL, (void *) platform,
    127             str_size(platform));
     127            str_bytes(platform));
    128128
    129129        niagarain_init();
  • kernel/genarch/src/multiboot/multiboot.c

    rd066259 r08e103d4  
    5151        const char *end = str_chr(cmd_line, ' ');
    5252        if (end == NULL)
    53                 end = cmd_line + str_size(cmd_line);
     53                end = cmd_line + str_bytes(cmd_line);
    5454
    5555        /*
     
    8888        }
    8989
    90         const char *end = cmd_line + str_size(cmd_line);
     90        const char *end = cmd_line + str_bytes(cmd_line);
    9191
    9292        /* Skip the space(s). */
  • kernel/genarch/src/ofw/ofw_tree.c

    rd066259 r08e103d4  
    250250        size_t j;
    251251
    252         for (size_t i = 1; (i < str_size(path)) && (node); i = j + 1) {
     252        for (size_t i = 1; (i < str_bytes(path)) && (node); i = j + 1) {
    253253                j = i;
    254                 while (j < str_size(path) && path[j] != '/')
     254                while (j < str_bytes(path) && path[j] != '/')
    255255                        j++;
    256256
     
    342342        *size = 0;
    343343        for (size_t i = 0; i < node->properties; i++)
    344                 *size += str_size(node->property[i].name) + 1 +
     344                *size += str_bytes(node->property[i].name) + 1 +
    345345                    sizeof(node->property[i].size) + node->property[i].size;
    346346
     
    359359                /* Property name */
    360360                str_cpy(dump + pos, *size - pos, node->property[i].name);
    361                 pos += str_size(node->property[i].name) + 1;
     361                pos += str_bytes(node->property[i].name) + 1;
    362362
    363363                /* Value size */
     
    393393                if ((cur->parent) && (path))
    394394                        snprintf(cur_path, PATH_MAX_LEN, "%s.%s", path, cur->da_name);
    395                 else if (!str_size(cur->da_name))
     395                else if (!str_bytes(cur->da_name))
    396396                        snprintf(cur_path, PATH_MAX_LEN, "firmware.ofw");
    397397                else
  • kernel/generic/include/str.h

    rd066259 r08e103d4  
    7272extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
    7373
    74 extern size_t str_size(const char *str);
    75 extern size_t wstr_size(const wchar_t *str);
     74extern size_t str_bytes(const char *str);
     75extern size_t wstr_bytes(const wchar_t *str);
    7676
    77 extern size_t str_lsize(const char *str, size_t max_len);
    78 extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
     77extern size_t str_lbytes(const char *str, size_t max_len);
     78extern size_t wstr_lbytes(const wchar_t *str, size_t max_len);
    7979
    80 extern size_t str_length(const char *str);
    81 extern size_t wstr_length(const wchar_t *wstr);
     80extern size_t str_code_points(const char *str);
     81extern size_t wstr_code_points(const wchar_t *wstr);
    8282
    83 extern size_t str_nlength(const char *str, size_t size);
    84 extern size_t wstr_nlength(const wchar_t *str, size_t size);
     83extern size_t str_ncode_points(const char *str, size_t size);
     84extern size_t wstr_ncode_points(const wchar_t *str, size_t size);
    8585
    8686extern bool ascii_check(wchar_t ch);
  • kernel/generic/src/console/cmd.c

    rd066259 r08e103d4  
    668668        list_foreach(cmd_list, link, cmd_info_t, hlp) {
    669669                spinlock_lock(&hlp->lock);
    670                 if (str_length(hlp->name) > len)
    671                         len = str_length(hlp->name);
     670                if (str_code_points(hlp->name) > len)
     671                        len = str_code_points(hlp->name);
    672672                spinlock_unlock(&hlp->lock);
    673673        }
     
    919919                spinlock_lock(&hlp->lock);
    920920
    921                 if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
     921                if (str_lcmp(hlp->name, (const char *) argv->buffer, str_code_points(hlp->name)) == 0) {
    922922                        printf("%s - %s\n", hlp->name, hlp->description);
    923923                        if (hlp->help)
     
    14861486
    14871487        for (test = tests; test->name != NULL; test++) {
    1488                 if (str_length(test->name) > len)
    1489                         len = str_length(test->name);
     1488                if (str_code_points(test->name) > len)
     1489                        len = str_code_points(test->name);
    14901490        }
    14911491
  • kernel/generic/src/console/console.c

    rd066259 r08e103d4  
    271271
    272272                                count--;
    273                                 offset = str_lsize(buf, count);
     273                                offset = str_lbytes(buf, count);
    274274                                buf[offset] = 0;
    275275                        }
  • kernel/generic/src/console/kconsole.c

    rd066259 r08e103d4  
    167167{
    168168        link_t **startpos = (link_t **) ctx;
    169         size_t namelen = str_length(name);
     169        size_t namelen = str_code_points(name);
    170170
    171171        spinlock_lock(&cmd_lock);
     
    178178
    179179                const char *curname = hlp->name;
    180                 if (str_length(curname) < namelen)
     180                if (str_code_points(curname) < namelen)
    181181                        continue;
    182182
     
    187187
    188188                        spinlock_unlock(&cmd_lock);
    189                         return (curname + str_lsize(curname, namelen));
     189                        return (curname + str_lbytes(curname, namelen));
    190190                }
    191191        }
     
    233233
    234234        while ((hint = hints_enum(name, NULL, &pos))) {
    235                 if ((found == 0) || (str_length(hint) > str_length(output)))
     235                if ((found == 0) || (str_code_points(hint) > str_code_points(output)))
    236236                        str_cpy(output, MAX_CMDLINE, hint);
    237237
     
    249249        }
    250250
    251         if ((found > 1) && (str_length(output) != 0)) {
     251        if ((found > 1) && (str_code_points(output) != 0)) {
    252252                printf("\n");
    253253                pos = NULL;
     
    358358                                putwchar('\b');
    359359                                printf("%ls ", current + position);
    360                                 print_cc('\b', wstr_length(current) - position + 1);
     360                                print_cc('\b', wstr_code_points(current) - position + 1);
    361361                                continue;
    362362                        }
     
    440440                                printf("%s> ", prompt);
    441441                                printf("%ls", current);
    442                                 position += str_length(tmp);
    443                                 print_cc('\b', wstr_length(current) - position);
     442                                position += str_code_points(tmp);
     443                                print_cc('\b', wstr_code_points(current) - position);
    444444                                continue;
    445445                        }
     
    448448
    449449                        printf("%ls", current + position);
    450                         position += str_length(tmp);
    451                         print_cc('\b', wstr_length(current) - position);
    452 
    453                         if (position == wstr_length(current)) {
     450                        position += str_code_points(tmp);
     451                        print_cc('\b', wstr_code_points(current) - position);
     452
     453                        if (position == wstr_code_points(current)) {
    454454                                /* Insert a space after the last completed argument */
    455455                                if (wstr_linsert(current, ' ', position, MAX_CMDLINE)) {
     
    472472                if (ch == U_RIGHT_ARROW) {
    473473                        /* Right */
    474                         if (position < wstr_length(current)) {
     474                        if (position < wstr_code_points(current)) {
    475475                                putwchar(current[position]);
    476476                                position++;
     
    482482                        /* Up, down */
    483483                        print_cc('\b', position);
    484                         print_cc(' ', wstr_length(current));
    485                         print_cc('\b', wstr_length(current));
     484                        print_cc(' ', wstr_code_points(current));
     485                        print_cc('\b', wstr_code_points(current));
    486486
    487487                        if (ch == U_UP_ARROW) {
     
    498498                        current = history[history_pos];
    499499                        printf("%ls", current);
    500                         position = wstr_length(current);
     500                        position = wstr_code_points(current);
    501501                        continue;
    502502                }
     
    512512                        /* End */
    513513                        printf("%ls", current + position);
    514                         position = wstr_length(current);
     514                        position = wstr_code_points(current);
    515515                        continue;
    516516                }
     
    518518                if (ch == U_DELETE) {
    519519                        /* Delete */
    520                         if (position == wstr_length(current))
     520                        if (position == wstr_code_points(current))
    521521                                continue;
    522522
    523523                        if (wstr_remove(current, position)) {
    524524                                printf("%ls ", current + position);
    525                                 print_cc('\b', wstr_length(current) - position + 1);
     525                                print_cc('\b', wstr_code_points(current) - position + 1);
    526526                        }
    527527                        continue;
     
    531531                        printf("%ls", current + position);
    532532                        position++;
    533                         print_cc('\b', wstr_length(current) - position);
    534                 }
    535         }
    536 
    537         if (wstr_length(current) > 0) {
     533                        print_cc('\b', wstr_code_points(current) - position);
     534                }
     535        }
     536
     537        if (wstr_code_points(current) > 0) {
    538538                history_pos++;
    539539                history_pos = history_pos % KCONSOLE_HISTORY;
     
    690690
    691691                if (str_lcmp(hlp->name, cmdline + start,
    692                     max(str_length(hlp->name),
    693                     str_nlength(cmdline + start, (size_t) (end - start)))) == 0) {
     692                    max(str_code_points(hlp->name),
     693                    str_ncode_points(cmdline + start, (size_t) (end - start)))) == 0) {
    694694                        cmd = hlp;
    695695                        break;
     
    826826        while (true) {
    827827                wchar_t *tmp = clever_readline((char *) prompt, stdin, buffer);
    828                 size_t len = wstr_length(tmp);
     828                size_t len = wstr_code_points(tmp);
    829829                if (!len)
    830830                        continue;
  • kernel/generic/src/debug/symtab.c

    rd066259 r08e103d4  
    120120static const char *symtab_search_one(const char *name, size_t *startpos)
    121121{
    122         size_t namelen = str_length(name);
     122        size_t namelen = str_code_points(name);
    123123
    124124        size_t pos;
     
    131131                        continue;
    132132
    133                 if (str_length(curname) < namelen)
     133                if (str_code_points(curname) < namelen)
    134134                        continue;
    135135
    136136                if (str_lcmp(name, curname, namelen) == 0) {
    137137                        *startpos = pos;
    138                         return (curname + str_lsize(curname, namelen));
     138                        return (curname + str_lbytes(curname, namelen));
    139139                }
    140140        }
     
    164164
    165165        while ((hint = symtab_search_one(name, &pos))) {
    166                 if (str_length(hint) == 0) {
     166                if (str_code_points(hint) == 0) {
    167167                        *addr = uint64_t_le2host(symbol_table[pos].address_le);
    168168                        found++;
     
    206206{
    207207#ifdef CONFIG_SYMTAB
    208         size_t len = str_length(input);
     208        size_t len = str_code_points(input);
    209209        struct symtab_entry **entry = (struct symtab_entry **)ctx;
    210210
     
    220220                        continue;
    221221
    222                 if (str_length(curname) < len)
     222                if (str_code_points(curname) < len)
    223223                        continue;
    224224
     
    227227                        if (help)
    228228                                *help = NULL;
    229                         return (curname + str_lsize(curname, len));
     229                        return (curname + str_lbytes(curname, len));
    230230                }
    231231        }
  • kernel/generic/src/lib/str.c

    rd066259 r08e103d4  
    288288 *
    289289 */
    290 size_t str_size(const char *str)
     290size_t str_bytes(const char *str)
    291291{
    292292        size_t size = 0;
     
    308308 *
    309309 */
    310 size_t wstr_size(const wchar_t *str)
    311 {
    312         return (wstr_length(str) * sizeof(wchar_t));
     310size_t wstr_bytes(const wchar_t *str)
     311{
     312        return (wstr_code_points(str) * sizeof(wchar_t));
    313313}
    314314
     
    326326 *
    327327 */
    328 size_t str_lsize(const char *str, size_t max_len)
     328size_t str_lbytes(const char *str, size_t max_len)
    329329{
    330330        size_t len = 0;
     
    354354 *
    355355 */
    356 size_t wstr_lsize(const wchar_t *str, size_t max_len)
    357 {
    358         return (wstr_nlength(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
     356size_t wstr_lbytes(const wchar_t *str, size_t max_len)
     357{
     358        return (wstr_ncode_points(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
    359359}
    360360
     
    366366 *
    367367 */
    368 size_t str_length(const char *str)
     368size_t str_code_points(const char *str)
    369369{
    370370        size_t len = 0;
     
    384384 *
    385385 */
    386 size_t wstr_length(const wchar_t *wstr)
     386size_t wstr_code_points(const wchar_t *wstr)
    387387{
    388388        size_t len = 0;
     
    402402 *
    403403 */
    404 size_t str_nlength(const char *str, size_t size)
     404size_t str_ncode_points(const char *str, size_t size)
    405405{
    406406        size_t len = 0;
     
    421421 *
    422422 */
    423 size_t wstr_nlength(const wchar_t *str, size_t size)
     423size_t wstr_ncode_points(const wchar_t *str, size_t size)
    424424{
    425425        size_t len = 0;
     
    508508 * Do a char-by-char comparison of two NULL-terminated strings.
    509509 * The strings are considered equal iff
    510  * min(str_length(s1), max_len) == min(str_length(s2), max_len)
     510 * min(str_code_points(s1), max_len) == min(str_code_points(s2), max_len)
    511511 * and both strings consist of the same sequence of characters,
    512512 * up to max_len characters.
     
    690690bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos)
    691691{
    692         size_t len = wstr_length(str);
     692        size_t len = wstr_code_points(str);
    693693
    694694        if ((pos > len) || (pos + 1 > max_pos))
     
    718718bool wstr_remove(wchar_t *str, size_t pos)
    719719{
    720         size_t len = wstr_length(str);
     720        size_t len = wstr_code_points(str);
    721721
    722722        if (pos >= len)
     
    748748char *str_dup(const char *src)
    749749{
    750         size_t size = str_size(src) + 1;
     750        size_t size = str_bytes(src) + 1;
    751751        char *dest = malloc(size);
    752752        if (!dest)
     
    779779char *str_ndup(const char *src, size_t n)
    780780{
    781         size_t size = str_size(src);
     781        size_t size = str_bytes(src);
    782782        if (size > n)
    783783                size = n;
  • kernel/generic/src/main/kinit.c

    rd066259 r08e103d4  
    193193        for (i = 0; i < init.cnt; i++) {
    194194                const char *arguments = init.tasks[i].arguments;
    195                 if (str_length(arguments) == 0)
    196                         continue;
    197                 if (str_length(init.tasks[i].name) == 0)
    198                         continue;
    199                 size_t arguments_size = str_size(arguments);
     195                if (str_code_points(arguments) == 0)
     196                        continue;
     197                if (str_code_points(init.tasks[i].name) == 0)
     198                        continue;
     199                size_t arguments_size = str_bytes(arguments);
    200200
    201201                void *arguments_copy = malloc(arguments_size);
  • kernel/generic/src/main/main.c

    rd066259 r08e103d4  
    279279        sys_waitq_init();
    280280
    281         sysinfo_set_item_data("boot_args", NULL, bargs, str_size(bargs) + 1);
     281        sysinfo_set_item_data("boot_args", NULL, bargs, str_bytes(bargs) + 1);
    282282
    283283        if (init.cnt > 0) {
  • kernel/generic/src/printf/printf_core.c

    rd066259 r08e103d4  
    156156{
    157157        if (str == NULL)
    158                 return printf_putnchars(nullstr, str_size(nullstr), ps);
    159 
    160         return ps->str_write((void *) str, str_size(str), ps->data);
     158                return printf_putnchars(nullstr, str_bytes(nullstr), ps);
     159
     160        return ps->str_write((void *) str, str_bytes(str), ps->data);
    161161}
    162162
     
    285285
    286286        /* Print leading spaces. */
    287         size_t strw = str_length(str);
     287        size_t strw = str_code_points(str);
    288288        if ((precision == 0) || (precision > strw))
    289289                precision = strw;
     
    301301        /* Part of @a str fitting into the alloted space. */
    302302        int retval;
    303         size_t size = str_lsize(str, precision);
     303        size_t size = str_lbytes(str, precision);
    304304        if ((retval = printf_putnchars(str, size, ps)) < 0)
    305305                return -counter;
     
    333333
    334334        /* Print leading spaces. */
    335         size_t strw = wstr_length(str);
     335        size_t strw = wstr_code_points(str);
    336336        if ((precision == 0) || (precision > strw))
    337337                precision = strw;
     
    349349        /* Part of @a wstr fitting into the alloted space. */
    350350        int retval;
    351         size_t size = wstr_lsize(str, precision);
     351        size_t size = wstr_lbytes(str, precision);
    352352        if ((retval = printf_wputnchars(str, size, ps)) < 0)
    353353                return -counter;
  • kernel/generic/src/sysinfo/sysinfo.c

    rd066259 r08e103d4  
    530530                if (spaces == 0) {
    531531                        printf("%s", cur->name);
    532                         length = str_length(cur->name);
     532                        length = str_code_points(cur->name);
    533533                } else {
    534534                        sysinfo_indent(spaces);
    535535                        printf(".%s", cur->name);
    536                         length = str_length(cur->name) + 1;
     536                        length = str_code_points(cur->name) + 1;
    537537                }
    538538
     
    747747                size_t size = 0;
    748748                for (sysinfo_item_t *cur = subtree; cur; cur = cur->next)
    749                         size += str_size(cur->name) + 1;
     749                        size += str_bytes(cur->name) + 1;
    750750
    751751                if (dry_run) {
     
    762762                        for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) {
    763763                                str_cpy(names + pos, size - pos, cur->name);
    764                                 pos += str_size(cur->name) + 1;
     764                                pos += str_bytes(cur->name) + 1;
    765765                        }
    766766
  • kernel/generic/src/udebug/udebug_ops.c

    rd066259 r08e103d4  
    432432errno_t udebug_name_read(char **data, size_t *data_size)
    433433{
    434         size_t name_size = str_size(TASK->name) + 1;
     434        size_t name_size = str_bytes(TASK->name) + 1;
    435435
    436436        *data = malloc(name_size);
  • kernel/test/test.c

    rd066259 r08e103d4  
    6666    void **ctx)
    6767{
    68         size_t len = str_length(input);
     68        size_t len = str_code_points(input);
    6969        test_t **test = (test_t **) ctx;
    7070
     
    7575                const char *curname = (*test)->name;
    7676
    77                 if (str_length(curname) < len)
     77                if (str_code_points(curname) < len)
    7878                        continue;
    7979
     
    8282                        if (help)
    8383                                *help = (*test)->desc;
    84                         return (curname + str_lsize(curname, len));
     84                        return (curname + str_lbytes(curname, len));
    8585                }
    8686        }
Note: See TracChangeset for help on using the changeset viewer.