Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4207 → Rev 4208

/trunk/kernel/generic/include/string.h
42,7 → 42,7
extern char invalch;
 
extern wchar_t chr_decode(const char *, size_t *, size_t);
extern bool chr_encode(const wchar_t, char *, size_t *, size_t);
extern int chr_encode(const wchar_t, char *, size_t *, size_t);
 
extern size_t str_size(const char *str);
extern size_t str_lsize(const char *, count_t);
/trunk/kernel/generic/src/printf/vsnprintf.c
36,6 → 36,7
#include <printf/printf_core.h>
#include <string.h>
#include <memstr.h>
#include <errno.h>
 
typedef struct {
size_t size; /* Total size of the buffer (in bytes) */
86,7 → 87,7
while (index < size) {
wchar_t uc = chr_decode(str, &index, size);
 
if (!chr_encode(uc, data->dst, &data->len, data->size - 1))
if (chr_encode(uc, data->dst, &data->len, data->size - 1) != EOK)
break;
}
146,7 → 147,7
return ((int) size);
}
if (!chr_encode(str[index], data->dst, &data->len, data->size - 1))
if (chr_encode(str[index], data->dst, &data->len, data->size - 1) != EOK)
break;
index++;
/trunk/kernel/generic/src/lib/string.c
40,6 → 40,7
#include <cpu.h>
#include <arch/asm.h>
#include <arch.h>
#include <errno.h>
#include <console/kconsole.h>
 
char invalch = '?';
140,11 → 141,11
* @param offset Offset (in bytes) where to start writing.
* @param sz Size of the output buffer.
*
* @return True if the character was encoded successfully or false if there
* was not enough space in the output buffer or the character code
* was invalid.
* @return EOK if the character was encoded successfully, EOVERFLOW if there
* was not enough space in the output buffer or EINVAL if the character
* code was invalid.
*/
bool chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz)
int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz)
{
uint32_t cc; /* Unsigned version of ch. */
 
153,10 → 154,10
int i;
 
if (*offset >= sz)
return false;
return EOVERFLOW;
 
if (ch < 0)
return false;
return EINVAL;
 
/* Bit operations should only be done on unsigned numbers. */
cc = (uint32_t) ch;
176,12 → 177,12
cbytes = 3;
} else {
/* Codes longer than 21 bits are not supported. */
return false;
return EINVAL;
}
 
/* Check for available space in buffer. */
if (*offset + cbytes >= sz)
return false;
return EOVERFLOW;
 
/* Encode continuation bytes. */
for (i = cbytes; i > 0; --i) {
195,7 → 196,7
/* Advance offset. */
*offset += (1 + cbytes);
return true;
return EOK;
}
 
/** Get size of string, with length limit.