Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4266 → Rev 4267

/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