Changeset f4b1535 in mainline


Ignore:
Timestamp:
2009-04-09T23:04:10Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6eb2e96
Parents:
095003a8
Message:

str_ncpy() vs str_cpy(). TODO: The same in userspace.

Location:
kernel
Files:
12 edited

Legend:

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

    r095003a8 rf4b1535  
    6363                init.tasks[i].addr = bootinfo->tasks[i].addr;
    6464                init.tasks[i].size = bootinfo->tasks[i].size;
    65                 str_ncpy(init.tasks[i].name, bootinfo->tasks[i].name,
    66                         CONFIG_TASK_NAME_BUFLEN);
     65                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
     66                    bootinfo->tasks[i].name);
    6767        }
    6868}
  • kernel/arch/ia64/src/ia64.c

    r095003a8 rf4b1535  
    8888                    VRN_MASK;
    8989                init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
    90                 str_ncpy(init.tasks[i].name, bootinfo->taskmap.tasks[i].name,
    91                         CONFIG_TASK_NAME_BUFLEN);
     90                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
     91                    bootinfo->taskmap.tasks[i].name);
    9292        }
    9393}
  • kernel/arch/mips32/src/mips32.c

    r095003a8 rf4b1535  
    9292                init.tasks[i].addr = bootinfo->tasks[i].addr;
    9393                init.tasks[i].size = bootinfo->tasks[i].size;
    94                 str_ncpy(init.tasks[i].name, bootinfo->tasks[i].name,
    95                         CONFIG_TASK_NAME_BUFLEN);
     94                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
     95                    bootinfo->tasks[i].name);
    9696        }
    9797       
  • kernel/arch/ppc32/src/ppc32.c

    r095003a8 rf4b1535  
    6262                init.tasks[i].addr = PA2KA(bootinfo.taskmap.tasks[i].addr);
    6363                init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
    64                 str_ncpy(init.tasks[i].name, bootinfo.taskmap.tasks[i].name,
    65                         CONFIG_TASK_NAME_BUFLEN);
     64                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
     65                    bootinfo.taskmap.tasks[i].name);
    6666        }
    6767}
  • kernel/arch/sparc64/src/sparc64.c

    r095003a8 rf4b1535  
    6262                init.tasks[i].addr = (uintptr_t) bootinfo.taskmap.tasks[i].addr;
    6363                init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
    64                 str_ncpy(init.tasks[i].name, bootinfo.taskmap.tasks[i].name,
    65                         CONFIG_TASK_NAME_BUFLEN);
     64                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
     65                    bootinfo.taskmap.tasks[i].name);
    6666        }
    6767       
  • kernel/genarch/src/multiboot/multiboot.c

    r095003a8 rf4b1535  
    7070       
    7171        /* Copy the command. */
    72         str_ncpy(buf, start, min(sz, (size_t) (end - start) + 1));
     72        str_ncpy(buf, sz, start, (size_t) (end - start));
    7373}
    7474
  • kernel/generic/include/string.h

    r095003a8 rf4b1535  
    8787extern int str_lcmp(const char *s1, const char *s2, count_t max_len);
    8888
    89 extern void str_ncpy(char *dst, const char *src, size_t size);
     89extern void str_cpy(char *dest, size_t size, const char *src);
     90extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
    9091extern void wstr_nstr(char *dst, const wchar_t *src, size_t size);
    9192
  • kernel/generic/src/console/kconsole.c

    r095003a8 rf4b1535  
    215215        while ((hint = cmdtab_search_one(name, &pos))) {
    216216                if ((found == 0) || (str_length(output) > str_length(hint)))
    217                         str_ncpy(output, hint, MAX_CMDLINE);
     217                        str_cpy(output, MAX_CMDLINE, hint);
    218218               
    219219                pos = pos->next;
     
    232232       
    233233        if (found > 0)
    234                 str_ncpy(input, output, size);
     234                str_cpy(input, size, output);
    235235       
    236236        return found;
     
    439439        if ((text[0] < '0') || (text[0] > '9')) {
    440440                char symname[MAX_SYMBOL_NAME];
    441                 str_ncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME));
     441                str_ncpy(symname, MAX_SYMBOL_NAME, text, len + 1);
    442442               
    443443                uintptr_t symaddr;
     
    581581                case ARG_TYPE_STRING:
    582582                        buf = (char *) cmd->argv[i].buffer;
    583                         str_ncpy(buf, cmdline + start,
    584                             min((end - start) + 1, cmd->argv[i].len));
     583                        str_ncpy(buf, cmd->argv[i].len, cmdline + start,
     584                            (end - start) + 1);
    585585                        break;
    586586                case ARG_TYPE_INT:
     
    593593                                if (cmdline[end - 1] == '"') {
    594594                                        buf = (char *) cmd->argv[i].buffer;
    595                                         str_ncpy(buf, cmdline + start + 1,
    596                                             min((end - start) - 1, cmd->argv[i].len));
     595                                        str_ncpy(buf, cmd->argv[i].len,
     596                                            cmdline + start + 1,
     597                                            (end - start) - 1);
    597598                                        cmd->argv[i].intval = (unative_t) buf;
    598599                                        cmd->argv[i].vartype = ARG_TYPE_STRING;
  • kernel/generic/src/debug/symtab.c

    r095003a8 rf4b1535  
    226226        while ((hint = symtab_search_one(name, &pos))) {
    227227                if ((found == 0) || (str_length(output) > str_length(hint)))
    228                         str_ncpy(output, hint, MAX_SYMBOL_NAME);
     228                        str_cpy(output, MAX_SYMBOL_NAME, hint);
    229229               
    230230                pos++;
     
    242242       
    243243        if (found > 0)
    244                 str_ncpy(input, output, size);
     244                str_cpy(input, size, output);
    245245       
    246246        return found;
  • kernel/generic/src/lib/string.c

    r095003a8 rf4b1535  
    529529}
    530530
    531 /** Copy NULL-terminated string.
    532  *
    533  * Copy source string @a src to destination buffer @a dst.
    534  * No more than @a size bytes are written. NULL-terminator is always
    535  * written after the last succesfully copied character (i.e. if the
    536  * destination buffer is has at least 1 byte, it will be always
    537  * NULL-terminated).
    538  *
    539  * @param src   Source string.
     531/** Copy string.
     532 *
     533 * Copy source string @a src to destination buffer @a dest.
     534 * No more than @a size bytes are written. If the size of the output buffer
     535 * is at least one byte, the output string will always be well-formed, i.e.
     536 * null-terminated and containing only complete characters.
     537 *
    540538 * @param dst   Destination buffer.
    541539 * @param count Size of the destination buffer.
    542  *
    543  */
    544 void str_ncpy(char *dst, const char *src, size_t size)
    545 {
    546         /* No space for the NULL-terminator in the buffer */
     540 * @param src   Source string.
     541 */
     542void str_cpy(char *dest, size_t size, const char *src)
     543{
     544        wchar_t ch;
     545        size_t src_off;
     546        size_t dest_off;
     547
     548        /* No space for the NULL-terminator in the buffer. */
    547549        if (size == 0)
    548550                return;
    549551       
     552        src_off = 0;
     553        dest_off = 0;
     554
     555        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
     556                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
     557                        break;
     558        }
     559
     560        dest[dest_off] = '\0';
     561}
     562
     563/** Copy size-limited substring.
     564 *
     565 * Copy source string @a src to destination buffer @a dest.
     566 * No more than @a size bytes are written. If the size of the output buffer
     567 * is at least one byte, the output string will always be well-formed, i.e.
     568 * null-terminated and containing only complete characters.
     569 *
     570 * No more than @a n bytes are read from the input string, so it does not
     571 * have to be null-terminated.
     572 *
     573 * @param dst   Destination buffer.
     574 * @param count Size of the destination buffer.
     575 * @param src   Source string.
     576 */
     577void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     578{
    550579        wchar_t ch;
    551         size_t str_off = 0;
    552         size_t dst_off = 0;
    553        
    554         while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
    555                 if (chr_encode(ch, dst, &dst_off, size) != EOK)
     580        size_t src_off;
     581        size_t dest_off;
     582
     583        /* No space for the null terminator in the buffer. */
     584        if (size == 0)
     585                return;
     586       
     587        src_off = 0;
     588        dest_off = 0;
     589
     590        while ((ch = str_decode(src, &src_off, n)) != 0) {
     591                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    556592                        break;
    557593        }
    558        
    559         if (dst_off >= size)
    560                 dst[size - 1] = 0;
    561         else
    562                 dst[dst_off] = 0;
     594
     595        dest[dest_off] = '\0';
    563596}
    564597
  • kernel/generic/src/main/kinit.c

    r095003a8 rf4b1535  
    191191               
    192192                ASSERT(TASK_NAME_BUFLEN >= INIT_PREFIX_LEN);
    193                 str_ncpy(namebuf, INIT_PREFIX, TASK_NAME_BUFLEN);
    194                 str_ncpy(namebuf + INIT_PREFIX_LEN, name,
    195                     TASK_NAME_BUFLEN - INIT_PREFIX_LEN);
    196                
     193                str_cpy(namebuf, TASK_NAME_BUFLEN, INIT_PREFIX);
     194                str_cpy(namebuf + INIT_PREFIX_LEN,
     195                    TASK_NAME_BUFLEN - INIT_PREFIX_LEN, name);
     196
    197197                int rc = program_create_from_image((void *) init.tasks[i].addr,
    198198                    namebuf, &programs[i]);
  • kernel/generic/src/proc/task.c

    r095003a8 rf4b1535  
    274274                return (unative_t) rc;
    275275
    276         namebuf[name_len] = 0;
    277         str_ncpy(TASK->name, namebuf, TASK_NAME_BUFLEN);
     276        namebuf[name_len] = '\0';
     277        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    278278
    279279        return EOK;
Note: See TracChangeset for help on using the changeset viewer.