Changeset 08e103d4 in mainline for uspace/app


Ignore:
Timestamp:
2019-02-05T18:26:05Z (7 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:
uspace/app
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rd066259 r08e103d4  
    188188        dentry_type_t dest_type = get_type(dest);
    189189
    190         const size_t src_len = str_size(src);
     190        const size_t src_len = str_bytes(src);
    191191
    192192        if (src_type == TYPE_FILE) {
     
    214214                        dest_type = get_type(dest_path);
    215215                } else if (dest_type == TYPE_NONE) {
    216                         if (dest_path[str_size(dest_path) - 1] == '/') {
     216                        if (dest_path[str_bytes(dest_path) - 1] == '/') {
    217217                                /* e.g. cp /textdemo /data/dirnotexists/ */
    218218
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rd066259 r08e103d4  
    174174
    175175                /* fill the name field */
    176                 tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1);
     176                tosort[nbdirs].name = (char *) malloc(str_bytes(dp->d_name) + 1);
    177177                if (!tosort[nbdirs].name) {
    178178                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
     
    180180                }
    181181
    182                 str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name);
     182                str_cpy(tosort[nbdirs].name, str_bytes(dp->d_name) + 1, dp->d_name);
    183183                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
    184184                buff[len] = '\0';
     
    264264                memset(subdir_path, 0, PATH_MAX);
    265265
    266                 if (str_size(subdir_path) + str_size(path) + 1 <= PATH_MAX)
     266                if (str_bytes(subdir_path) + str_bytes(path) + 1 <= PATH_MAX)
    267267                        str_append(subdir_path, PATH_MAX, path);
    268                 if (path[str_size(path) - 1] != '/' &&
    269                     str_size(subdir_path) + str_size(trailing_slash) + 1 <= PATH_MAX)
     268                if (path[str_bytes(path) - 1] != '/' &&
     269                    str_bytes(subdir_path) + str_bytes(trailing_slash) + 1 <= PATH_MAX)
    270270                        str_append(subdir_path, PATH_MAX, trailing_slash);
    271                 if (str_size(subdir_path) +
    272                     str_size(dir_list[i].name) + 1 <= PATH_MAX)
     271                if (str_bytes(subdir_path) +
     272                    str_bytes(dir_list[i].name) + 1 <= PATH_MAX)
    273273                        str_append(subdir_path, PATH_MAX, dir_list[i].name);
    274274
  • uspace/app/bdsh/cmds/modules/printf/printf.c

    rd066259 r08e103d4  
    135135
    136136        fmt = argv[1];
    137         fmt_sz = str_size(fmt);
     137        fmt_sz = str_bytes(fmt);
    138138        pos = 0;
    139139        carg = 2;
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rd066259 r08e103d4  
    302302        i = optind;
    303303        while (NULL != argv[i]) {
    304                 len = str_size(argv[i]) + 2;
     304                len = str_bytes(argv[i]) + 2;
    305305                buff = (char *) realloc(buff, len);
    306306                if (buff == NULL) {
  • uspace/app/bdsh/compl.c

    rd066259 r08e103d4  
    160160         * XXX: handle strings, etc.
    161161         */
    162         pref_size = str_lsize(stext, pos - *cstart);
     162        pref_size = str_lbytes(stext, pos - *cstart);
    163163        prefix = malloc(pref_size + 1);
    164164        if (prefix == NULL) {
     
    237237        }
    238238
    239         cs->prefix_len = str_length(cs->prefix);
     239        cs->prefix_len = str_code_points(cs->prefix);
    240240
    241241        tok_fini(&tok);
  • uspace/app/bdsh/tok.c

    rd066259 r08e103d4  
    6565
    6666        /* Prepare a buffer where all the token strings will be stored */
    67         size_t len = str_size(input) + max_tokens + 1;
     67        size_t len = str_bytes(input) + max_tokens + 1;
    6868        char *tmp = malloc(len);
    6969
  • uspace/app/date/date.c

    rd066259 r08e103d4  
    203203        uint32_t tmp;
    204204
    205         if (str_size(wdate) != 10) /* str_size("DD/MM/YYYY") == 10 */
     205        if (str_bytes(wdate) != 10) /* str_bytes("DD/MM/YYYY") == 10 */
    206206                return EINVAL;
    207207
     
    236236{
    237237        errno_t rc;
    238         size_t len = str_size(wtime);
     238        size_t len = str_bytes(wtime);
    239239        bool sec_present = len == 8;
    240240        uint32_t tmp;
    241241
    242         /* str_size("HH:MM") == 5 */
    243         /* str_size("HH:MM:SS") == 8 */
     242        /* str_bytes("HH:MM") == 5 */
     243        /* str_bytes("HH:MM:SS") == 8 */
    244244        if (len != 8 && len != 5)
    245245                return EINVAL;
  • uspace/app/edit/edit.c

    rd066259 r08e103d4  
    637637        asprintf(&str, "%s: %s", prompt, init_value);
    638638        status_display(str);
    639         console_set_pos(con, 1 + str_length(str), scr_rows - 1);
     639        console_set_pos(con, 1 + str_code_points(str), scr_rows - 1);
    640640        free(str);
    641641
    642642        console_set_style(con, STYLE_INVERTED);
    643643
    644         max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
     644        max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_code_points(prompt));
    645645        str_to_wstr(buffer, max_len + 1, init_value);
    646         nc = wstr_length(buffer);
     646        nc = wstr_code_points(buffer);
    647647        done = false;
    648648
     
    747747        do {
    748748                sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep);
    749                 bytes = str_size(buf);
     749                bytes = str_bytes(buf);
    750750
    751751                n_written = fwrite(buf, 1, bytes, f);
     
    783783                sheet_copy_out(doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
    784784                    &bep);
    785                 bytes = str_size(&buf[bpos]);
     785                bytes = str_bytes(&buf[bpos]);
    786786                bpos += bytes;
    787787                sp = bep;
     
    893893
    894894                console_set_pos(con, 0, i);
    895                 size = str_size(row_buf);
     895                size = str_bytes(row_buf);
    896896                pos = 0;
    897897                s_column = pane.sh_column;
     
    10121012                /* Compute position where we overwrite with '..\0' */
    10131013                if (fnw >= nextra + 2) {
    1014                         p = fname + str_lsize(fname, fnw - nextra - 2);
     1014                        p = fname + str_lbytes(fname, fnw - nextra - 2);
    10151015                } else {
    10161016                        p = fname;
     
    16091609{
    16101610        size_t offset = 0;
    1611         return str_decode(str, &offset, str_size(str));
     1611        return str_decode(str, &offset, str_bytes(str));
    16121612}
    16131613
  • uspace/app/edit/search.c

    rd066259 r08e103d4  
    5656        }
    5757
    58         search->pattern_length = wstr_length(p);
     58        search->pattern_length = wstr_code_points(p);
    5959
    6060        if (reverse) {
  • uspace/app/edit/sheet.c

    rd066259 r08e103d4  
    107107        char *newp;
    108108
    109         sz = str_size(str);
     109        sz = str_bytes(str);
    110110        if (sh->text_size + sz > sh->dbuf_size) {
    111111                /* Enlarge data buffer. */
  • uspace/app/fdisk/fdisk.c

    rd066259 r08e103d4  
    617617                        }
    618618
    619                         if (str_size(pinfo.label) > 0)
     619                        if (str_bytes(pinfo.label) > 0)
    620620                                label = pinfo.label;
    621621                        else
     
    10101010                }
    10111011
    1012                 if (str_size(pinfo.label) > 0)
     1012                if (str_bytes(pinfo.label) > 0)
    10131013                        label = pinfo.label;
    10141014                else
  • uspace/app/hbench/env.c

    rd066259 r08e103d4  
    4949{
    5050        param_t *param = hash_table_get_inst(item, param_t, link);
    51         return str_size(param->key);
     51        return str_bytes(param->key);
    5252}
    5353
     
    5555{
    5656        char *key_str = key;
    57         return str_size(key_str);
     57        return str_bytes(key_str);
    5858}
    5959
  • uspace/app/hbench/main.c

    rd066259 r08e103d4  
    291291        size_t len = 0;
    292292        for (size_t i = 0; i < benchmark_count; i++) {
    293                 size_t len_now = str_length(benchmarks[i]->name);
     293                size_t len_now = str_code_points(benchmarks[i]->name);
    294294                if (len_now > len)
    295295                        len = len_now;
  • uspace/app/kio/kio.c

    rd066259 r08e103d4  
    245245                }
    246246
    247                 kio_command(str, str_size(str));
     247                kio_command(str, str_bytes(str));
    248248                free(str);
    249249        }
  • uspace/app/lprint/lprint.c

    rd066259 r08e103d4  
    100100                ++argv;
    101101
    102                 rc = chardev_write(chardev, msg, str_size(msg), &nbytes);
     102                rc = chardev_write(chardev, msg, str_bytes(msg), &nbytes);
    103103                if (rc != EOK) {
    104104                        printf(NAME ": Failed sending data.\n");
     
    108108                sep = argc > 0 ? " " : "\n";
    109109
    110                 rc = chardev_write(chardev, sep, str_size(sep), &nbytes);
     110                rc = chardev_write(chardev, sep, str_bytes(sep), &nbytes);
    111111                if (rc != EOK) {
    112112                        printf(NAME ": Failed sending data.\n");
  • uspace/app/netecho/netecho.c

    rd066259 r08e103d4  
    139139
    140140        while (*msgs != NULL) {
    141                 rc = comm_send(*msgs, str_size(*msgs));
     141                rc = comm_send(*msgs, str_bytes(*msgs));
    142142                if (rc != EOK) {
    143143                        printf("[Failed sending data]\n");
  • uspace/app/nic/nic.c

    rd066259 r08e103d4  
    452452        }
    453453
    454         if (str_size(str) != 17) {
     454        if (str_bytes(str) != 17) {
    455455                printf("Invalid MAC address specified");
    456456                return EINVAL;
  • uspace/app/sbi/src/builtin/bi_string.c

    rd066259 r08e103d4  
    8686        assert(self_value_var->vc == vc_string);
    8787        str = self_value_var->u.string_v->value;
    88         str_l = os_str_length(str);
     88        str_l = os_str_code_points(str);
    8989
    9090#ifdef DEBUG_RUN_TRACE
     
    131131        assert(self_value_var->vc == vc_string);
    132132        str = self_value_var->u.string_v->value;
    133         str_l = os_str_length(str);
     133        str_l = os_str_code_points(str);
    134134
    135135        /* Get argument @a start. */
  • uspace/app/sbi/src/lex.c

    rd066259 r08e103d4  
    597597        lex_char_string_core(lex, cs_chr);
    598598
    599         len = os_str_length(strlit_buf);
     599        len = os_str_code_points(strlit_buf);
    600600        if (len != 1) {
    601601                printf("Character literal should contain one character, "
  • uspace/app/sbi/src/os/helenos.c

    rd066259 r08e103d4  
    6060        char *str;
    6161
    62         a_size = str_size(a);
    63         b_size = str_size(b);
     62        a_size = str_bytes(a);
     63        b_size = str_bytes(b);
    6464
    6565        str = malloc(a_size + b_size + 1);
     
    9696        wchar_t c;
    9797
    98         assert(start + length <= str_length(str));
     98        assert(start + length <= str_code_points(str));
    9999
    100100        offset = 0;
     
    106106        }
    107107
    108         size = str_lsize(str, length);
     108        size = str_lbytes(str, length);
    109109        slice = str_ndup(str + offset, size);
    110110
     
    128128 * @return      Number of characters in @a str.
    129129 */
    130 size_t os_str_length(const char *str)
    131 {
    132         return str_length(str);
     130size_t os_str_code_points(const char *str)
     131{
     132        return str_code_points(str);
    133133}
    134134
  • uspace/app/sbi/src/os/os.h

    rd066259 r08e103d4  
    3636int os_str_cmp(const char *a, const char *b);
    3737char *os_str_dup(const char *str);
    38 size_t os_str_length(const char *str);
     38size_t os_str_code_points(const char *str);
    3939errno_t os_str_get_char(const char *str, int index, int *out_char);
    4040char *os_chr_to_astr(wchar_t chr);
  • uspace/app/sbi/src/os/posix.c

    rd066259 r08e103d4  
    124124 * @return      Number of characters in @a str.
    125125 */
    126 size_t os_str_length(const char *str)
     126size_t os_str_code_points(const char *str)
    127127{
    128128        return strlen(str);
  • uspace/app/sportdmp/sportdmp.c

    rd066259 r08e103d4  
    5454
    5555        if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
    56                 size_t arg_offset = str_lsize(argv[arg], 7);
     56                size_t arg_offset = str_lbytes(argv[arg], 7);
    5757                char *arg_str = argv[arg] + arg_offset;
    58                 if (str_length(arg_str) == 0) {
     58                if (str_code_points(arg_str) == 0) {
    5959                        fprintf(stderr, "--baud requires an argument\n");
    6060                        syntax_print();
  • uspace/app/sysinfo/sysinfo.c

    rd066259 r08e103d4  
    129129        while (pos < size) {
    130130                /* Process each key with sanity checks */
    131                 size_t cur_size = str_nsize(keys + pos, size - pos);
     131                size_t cur_size = str_nbytes(keys + pos, size - pos);
    132132                if (keys[pos + cur_size] != 0)
    133133                        break;
    134134
    135                 size_t path_size = str_size(path) + cur_size + 2;
     135                size_t path_size = str_bytes(path) + cur_size + 2;
    136136                char *cur_path = (char *) malloc(path_size);
    137137                if (cur_path == NULL)
     
    143143                        print_spaces(spaces);
    144144                        printf(".%s\n", keys + pos);
    145                         length = str_length(keys + pos) + 1;
     145                        length = str_code_points(keys + pos) + 1;
    146146
    147147                        snprintf(cur_path, path_size, "%s.%s", path, keys + pos);
    148148                } else {
    149149                        printf("%s\n", keys + pos);
    150                         length = str_length(keys + pos);
     150                        length = str_code_points(keys + pos);
    151151
    152152                        snprintf(cur_path, path_size, "%s", keys + pos);
  • uspace/app/taskdump/elf_core.c

    rd066259 r08e103d4  
    177177        p_hdr[0].p_paddr = 0;
    178178        p_hdr[0].p_filesz = sizeof(elf_note_t) +
    179             ALIGN_UP((str_size("CORE") + 1), word_size) +
     179            ALIGN_UP((str_bytes("CORE") + 1), word_size) +
    180180            ALIGN_UP(sizeof(elf_prstatus_t), word_size);
    181181        p_hdr[0].p_memsz = 0;
     
    230230         * Write note header
    231231         */
    232         note.namesz = str_size("CORE") + 1;
     232        note.namesz = str_bytes("CORE") + 1;
    233233        note.descsz = sizeof(elf_prstatus_t);
    234234        note.type = NT_PRSTATUS;
  • uspace/app/tester/hw/serial/serial1.c

    rd066259 r08e103d4  
    198198        TPRINTF("Trying to write EOT banner to the serial device\n");
    199199
    200         size_t eot_size = str_size(EOT);
     200        size_t eot_size = str_bytes(EOT);
    201201        rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten);
    202202
  • uspace/app/tester/tester.c

    rd066259 r08e103d4  
    142142        test_t *test;
    143143        for (test = tests; test->name != NULL; test++) {
    144                 if (str_length(test->name) > len)
    145                         len = str_length(test->name);
     144                if (str_code_points(test->name) > len)
     145                        len = str_code_points(test->name);
    146146        }
    147147
  • uspace/app/tetris/screen.c

    rd066259 r08e103d4  
    321321void scr_msg(char *s, bool set)
    322322{
    323         int l = str_size(s);
     323        int l = str_bytes(s);
    324324
    325325        moveto(Rows - 2, ((Cols - l) >> 1) - 1);
  • uspace/app/tetris/tetris.c

    rd066259 r08e103d4  
    268268                        break;
    269269                case 'k':
    270                         if (str_size(keys = optarg) != 6)
     270                        if (str_bytes(keys = optarg) != 6)
    271271                                usage();
    272272                        break;
  • uspace/app/tmon/tests.c

    rd066259 r08e103d4  
    130130
    131131        if (params->transfer_size) {
    132                 char *str_size = tmon_format_size(params->transfer_size, "%.3f %s");
    133                 printf("Transfer size: %s\n", str_size);
    134                 free(str_size);
     132                char *str_bytes = tmon_format_size(params->transfer_size, "%.3f %s");
     133                printf("Transfer size: %s\n", str_bytes);
     134                free(str_bytes);
    135135        } else {
    136136                printf("Transfer size: (max. transfer size)\n");
  • uspace/app/usbinfo/list.c

    rd066259 r08e103d4  
    9898        /* Get handle of parent device */
    9999        devman_handle_t fh;
    100         path[str_size(path) - str_size(name) - 1] = '\0';
     100        path[str_bytes(path) - str_bytes(name) - 1] = '\0';
    101101        rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
    102102        if (rc != EOK) {
  • uspace/app/wavplay/wave.c

    rd066259 r08e103d4  
    151151{
    152152        assert(header);
    153 #define COPY_STR(dst, src)   memcpy(dst, src, str_size(src))
     153#define COPY_STR(dst, src)   memcpy(dst, src, str_bytes(src))
    154154
    155155        COPY_STR(&header->chunk_id, CHUNK_ID);
  • uspace/app/websrv/websrv.c

    rd066259 r08e103d4  
    227227static errno_t send_response(tcp_conn_t *conn, const char *msg)
    228228{
    229         size_t response_size = str_size(msg);
     229        size_t response_size = str_bytes(msg);
    230230
    231231        if (verbose)
     
    322322        char *end_uri = str_chr(uri, ' ');
    323323        if (end_uri == NULL) {
    324                 end_uri = reqline + str_size(reqline) - 2;
     324                end_uri = reqline + str_bytes(reqline) - 2;
    325325                assert(*end_uri == '\r');
    326326        }
Note: See TracChangeset for help on using the changeset viewer.