Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4254 → Rev 4267

/trunk/kernel/genarch/src/multiboot/multiboot.c
69,7 → 69,7
}
/* Copy the command. */
str_ncpy(buf, start, min(sz, (size_t) (end - start) + 1));
str_ncpy(buf, sz, start, (size_t) (end - start));
}
 
/** Parse multiboot information structure.
/trunk/kernel/generic/include/string.h
86,7 → 86,8
extern int str_cmp(const char *s1, const char *s2);
extern int str_lcmp(const char *s1, const char *s2, count_t max_len);
 
extern void str_ncpy(char *dst, const char *src, size_t size);
extern void str_cpy(char *dest, size_t size, const char *src);
extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
extern void wstr_nstr(char *dst, const wchar_t *src, size_t size);
 
extern const char *str_chr(const char *str, wchar_t ch);
/trunk/kernel/generic/src/main/kinit.c
190,10 → 190,10
name = "<unknown>";
ASSERT(TASK_NAME_BUFLEN >= INIT_PREFIX_LEN);
str_ncpy(namebuf, INIT_PREFIX, TASK_NAME_BUFLEN);
str_ncpy(namebuf + INIT_PREFIX_LEN, name,
TASK_NAME_BUFLEN - INIT_PREFIX_LEN);
str_cpy(namebuf, TASK_NAME_BUFLEN, INIT_PREFIX);
str_cpy(namebuf + INIT_PREFIX_LEN,
TASK_NAME_BUFLEN - INIT_PREFIX_LEN, name);
 
int rc = program_create_from_image((void *) init.tasks[i].addr,
namebuf, &programs[i]);
/trunk/kernel/generic/src/debug/symtab.c
225,7 → 225,7
while ((hint = symtab_search_one(name, &pos))) {
if ((found == 0) || (str_length(output) > str_length(hint)))
str_ncpy(output, hint, MAX_SYMBOL_NAME);
str_cpy(output, MAX_SYMBOL_NAME, hint);
pos++;
found++;
241,7 → 241,7
}
if (found > 0)
str_ncpy(input, output, size);
str_cpy(input, size, output);
return found;
/trunk/kernel/generic/src/console/kconsole.c
214,7 → 214,7
while ((hint = cmdtab_search_one(name, &pos))) {
if ((found == 0) || (str_length(output) > str_length(hint)))
str_ncpy(output, hint, MAX_CMDLINE);
str_cpy(output, MAX_CMDLINE, hint);
pos = pos->next;
found++;
231,7 → 231,7
}
if (found > 0)
str_ncpy(input, output, size);
str_cpy(input, size, output);
return found;
}
438,7 → 438,7
if ((text[0] < '0') || (text[0] > '9')) {
char symname[MAX_SYMBOL_NAME];
str_ncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME));
str_ncpy(symname, MAX_SYMBOL_NAME, text, len + 1);
uintptr_t symaddr;
int rc = symtab_addr_lookup(symname, &symaddr);
580,8 → 580,8
switch (cmd->argv[i].type) {
case ARG_TYPE_STRING:
buf = (char *) cmd->argv[i].buffer;
str_ncpy(buf, cmdline + start,
min((end - start) + 1, cmd->argv[i].len));
str_ncpy(buf, cmd->argv[i].len, cmdline + start,
(end - start) + 1);
break;
case ARG_TYPE_INT:
if (!parse_int_arg(cmdline + start, end - start,
592,8 → 592,9
if ((start < end - 1) && (cmdline[start] == '"')) {
if (cmdline[end - 1] == '"') {
buf = (char *) cmd->argv[i].buffer;
str_ncpy(buf, cmdline + start + 1,
min((end - start) - 1, cmd->argv[i].len));
str_ncpy(buf, cmd->argv[i].len,
cmdline + start + 1,
(end - start) - 1);
cmd->argv[i].intval = (unative_t) buf;
cmd->argv[i].vartype = ARG_TYPE_STRING;
} else {
/trunk/kernel/generic/src/proc/task.c
273,8 → 273,8
if (rc != 0)
return (unative_t) rc;
 
namebuf[name_len] = 0;
str_ncpy(TASK->name, namebuf, TASK_NAME_BUFLEN);
namebuf[name_len] = '\0';
str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
 
return EOK;
}
/trunk/kernel/generic/src/lib/string.c
528,38 → 528,71
 
}
 
/** Copy NULL-terminated string.
/** Copy string.
*
* Copy source string @a src to destination buffer @a dst.
* No more than @a size bytes are written. NULL-terminator is always
* written after the last succesfully copied character (i.e. if the
* destination buffer is has at least 1 byte, it will be always
* NULL-terminated).
* Copy source string @a src to destination buffer @a dest.
* No more than @a size bytes are written. If the size of the output buffer
* is at least one byte, the output string will always be well-formed, i.e.
* null-terminated and containing only complete characters.
*
* @param src Source string.
* @param dst Destination buffer.
* @param count Size of the destination buffer.
*
* @param src Source string.
*/
void str_ncpy(char *dst, const char *src, size_t size)
void str_cpy(char *dest, size_t size, const char *src)
{
/* No space for the NULL-terminator in the buffer */
wchar_t ch;
size_t src_off;
size_t dest_off;
 
/* No space for the NULL-terminator in the buffer. */
if (size == 0)
return;
src_off = 0;
dest_off = 0;
 
while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
break;
}
 
dest[dest_off] = '\0';
}
 
/** Copy size-limited substring.
*
* Copy source string @a src to destination buffer @a dest.
* No more than @a size bytes are written. If the size of the output buffer
* is at least one byte, the output string will always be well-formed, i.e.
* null-terminated and containing only complete characters.
*
* No more than @a n bytes are read from the input string, so it does not
* have to be null-terminated.
*
* @param dst Destination buffer.
* @param count Size of the destination buffer.
* @param src Source string.
*/
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
{
wchar_t ch;
size_t str_off = 0;
size_t dst_off = 0;
size_t src_off;
size_t dest_off;
 
/* No space for the null terminator in the buffer. */
if (size == 0)
return;
while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
if (chr_encode(ch, dst, &dst_off, size) != EOK)
src_off = 0;
dest_off = 0;
 
while ((ch = str_decode(src, &src_off, n)) != 0) {
if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
break;
}
if (dst_off >= size)
dst[size - 1] = 0;
else
dst[dst_off] = 0;
 
dest[dest_off] = '\0';
}
 
/** Copy NULL-terminated wide string to string
/trunk/kernel/arch/sparc64/src/sparc64.c
61,8 → 61,8
for (i = 0; i < bootinfo.taskmap.count; i++) {
init.tasks[i].addr = (uintptr_t) bootinfo.taskmap.tasks[i].addr;
init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
str_ncpy(init.tasks[i].name, bootinfo.taskmap.tasks[i].name,
CONFIG_TASK_NAME_BUFLEN);
str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
bootinfo.taskmap.tasks[i].name);
}
/* Copy boot allocations info. */
/trunk/kernel/arch/ia64/src/ia64.c
87,8 → 87,8
((unsigned long) bootinfo->taskmap.tasks[i].addr) |
VRN_MASK;
init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
str_ncpy(init.tasks[i].name, bootinfo->taskmap.tasks[i].name,
CONFIG_TASK_NAME_BUFLEN);
str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
bootinfo->taskmap.tasks[i].name);
}
}
 
/trunk/kernel/arch/arm32/src/arm32.c
62,8 → 62,8
for (i = 0; i < min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); ++i) {
init.tasks[i].addr = bootinfo->tasks[i].addr;
init.tasks[i].size = bootinfo->tasks[i].size;
str_ncpy(init.tasks[i].name, bootinfo->tasks[i].name,
CONFIG_TASK_NAME_BUFLEN);
str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
bootinfo->tasks[i].name);
}
}
 
/trunk/kernel/arch/ppc32/src/ppc32.c
61,8 → 61,8
for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
init.tasks[i].addr = PA2KA(bootinfo.taskmap.tasks[i].addr);
init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
str_ncpy(init.tasks[i].name, bootinfo.taskmap.tasks[i].name,
CONFIG_TASK_NAME_BUFLEN);
str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
bootinfo.taskmap.tasks[i].name);
}
}
 
/trunk/kernel/arch/mips32/src/mips32.c
91,8 → 91,8
for (i = 0; i < min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
init.tasks[i].addr = bootinfo->tasks[i].addr;
init.tasks[i].size = bootinfo->tasks[i].size;
str_ncpy(init.tasks[i].name, bootinfo->tasks[i].name,
CONFIG_TASK_NAME_BUFLEN);
str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
bootinfo->tasks[i].name);
}
for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {