Subversion Repositories HelenOS

Rev

Rev 4267 | Rev 4490 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4267 Rev 4281
Line 106... Line 106...
106
#include <cpu.h>
106
#include <cpu.h>
107
#include <arch/asm.h>
107
#include <arch/asm.h>
108
#include <arch.h>
108
#include <arch.h>
109
#include <errno.h>
109
#include <errno.h>
110
#include <align.h>
110
#include <align.h>
-
 
111
#include <debug.h>
111
 
112
 
112
/** Byte mask consisting of lowest @n bits (out of 8) */
113
/** Byte mask consisting of lowest @n bits (out of 8) */
113
#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
114
#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
114
 
115
 
115
/** Byte mask consisting of lowest @n bits (out of 32) */
116
/** Byte mask consisting of lowest @n bits (out of 32) */
Line 534... Line 535...
534
 * No more than @a size bytes are written. If the size of the output buffer
535
 * 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
 * is at least one byte, the output string will always be well-formed, i.e.
536
 * null-terminated and containing only complete characters.
537
 * null-terminated and containing only complete characters.
537
 *
538
 *
538
 * @param dst   Destination buffer.
539
 * @param dst   Destination buffer.
539
 * @param count Size of the destination buffer.
540
 * @param count Size of the destination buffer (must be > 0).
540
 * @param src   Source string.
541
 * @param src   Source string.
541
 */
542
 */
542
void str_cpy(char *dest, size_t size, const char *src)
543
void str_cpy(char *dest, size_t size, const char *src)
543
{
544
{
544
    wchar_t ch;
545
    wchar_t ch;
545
    size_t src_off;
546
    size_t src_off;
546
    size_t dest_off;
547
    size_t dest_off;
547
 
548
 
548
    /* No space for the NULL-terminator in the buffer. */
549
    /* There must be space for a null terminator in the buffer. */
549
    if (size == 0)
550
    ASSERT(size > 0);
550
        return;
-
 
551
   
551
   
552
    src_off = 0;
552
    src_off = 0;
553
    dest_off = 0;
553
    dest_off = 0;
554
 
554
 
555
    while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
555
    while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
Line 560... Line 560...
560
    dest[dest_off] = '\0';
560
    dest[dest_off] = '\0';
561
}
561
}
562
 
562
 
563
/** Copy size-limited substring.
563
/** Copy size-limited substring.
564
 *
564
 *
565
 * Copy source string @a src to destination buffer @a dest.
565
 * Copy prefix of string @a src of max. size @a size to destination buffer
566
 * No more than @a size bytes are written. If the size of the output buffer
566
 * @a dest. No more than @a size bytes are written. The output string will
567
 * is at least one byte, the output string will always be well-formed, i.e.
567
 * always be well-formed, i.e. null-terminated and containing only complete
568
 * null-terminated and containing only complete characters.
568
 * characters.
569
 *
569
 *
570
 * No more than @a n bytes are read from the input string, so it does not
570
 * No more than @a n bytes are read from the input string, so it does not
571
 * have to be null-terminated.
571
 * have to be null-terminated.
572
 *
572
 *
573
 * @param dst   Destination buffer.
573
 * @param dst   Destination buffer.
574
 * @param count Size of the destination buffer.
574
 * @param count Size of the destination buffer (must be > 0).
575
 * @param src   Source string.
575
 * @param src   Source string.
-
 
576
 * @param n Maximum number of bytes to read from @a src.
576
 */
577
 */
577
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
578
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
578
{
579
{
579
    wchar_t ch;
580
    wchar_t ch;
580
    size_t src_off;
581
    size_t src_off;
581
    size_t dest_off;
582
    size_t dest_off;
582
 
583
 
583
    /* No space for the null terminator in the buffer. */
584
    /* There must be space for a null terminator in the buffer. */
584
    if (size == 0)
585
    ASSERT(size > 0);
585
        return;
-
 
586
   
586
   
587
    src_off = 0;
587
    src_off = 0;
588
    dest_off = 0;
588
    dest_off = 0;
589
 
589
 
590
    while ((ch = str_decode(src, &src_off, n)) != 0) {
590
    while ((ch = str_decode(src, &src_off, n)) != 0) {