Subversion Repositories HelenOS

Rev

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

Rev 4234 Rev 4267
Line 526... Line 526...
526
 
526
 
527
    return 0;
527
    return 0;
528
 
528
 
529
}
529
}
530
 
530
 
531
/** Copy NULL-terminated string.
531
/** Copy string.
532
 *
532
 *
533
 * Copy source string @a src to destination buffer @a dst.
533
 * Copy source string @a src to destination buffer @a dest.
534
 * No more than @a size bytes are written. NULL-terminator is always
534
 * No more than @a size bytes are written. If the size of the output buffer
535
 * written after the last succesfully copied character (i.e. if the
535
 * is at least one byte, the output string will always be well-formed, i.e.
536
 * destination buffer is has at least 1 byte, it will be always
536
 * null-terminated and containing only complete characters.
537
 * NULL-terminated).
-
 
538
 *
537
 *
539
 * @param src   Source string.
-
 
540
 * @param dst   Destination buffer.
538
 * @param dst   Destination buffer.
541
 * @param count Size of the destination buffer.
539
 * @param count Size of the destination buffer.
542
 *
540
 * @param src   Source string.
543
 */
541
 */
544
void str_ncpy(char *dst, const char *src, size_t size)
542
void str_cpy(char *dest, size_t size, const char *src)
545
{
543
{
-
 
544
    wchar_t ch;
-
 
545
    size_t src_off;
-
 
546
    size_t dest_off;
-
 
547
 
546
    /* No space for the NULL-terminator in the buffer */
548
    /* No space for the NULL-terminator in the buffer. */
547
    if (size == 0)
549
    if (size == 0)
548
        return;
550
        return;
549
   
551
   
-
 
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
 */
-
 
577
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
-
 
578
{
550
    wchar_t ch;
579
    wchar_t ch;
551
    size_t str_off = 0;
580
    size_t src_off;
552
    size_t dst_off = 0;
581
    size_t dest_off;
-
 
582
 
-
 
583
    /* No space for the null terminator in the buffer. */
-
 
584
    if (size == 0)
-
 
585
        return;
553
   
586
   
-
 
587
    src_off = 0;
-
 
588
    dest_off = 0;
-
 
589
 
554
    while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
590
    while ((ch = str_decode(src, &src_off, n)) != 0) {
555
        if (chr_encode(ch, dst, &dst_off, size) != EOK)
591
        if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
556
            break;
592
            break;
557
    }
593
    }
558
   
594
 
559
    if (dst_off >= size)
-
 
560
        dst[size - 1] = 0;
-
 
561
    else
-
 
562
        dst[dst_off] = 0;
595
    dest[dest_off] = '\0';
563
}
596
}
564
 
597
 
565
/** Copy NULL-terminated wide string to string
598
/** Copy NULL-terminated wide string to string
566
 *
599
 *
567
 * Copy source wide string @a src to destination buffer @a dst.
600
 * Copy source wide string @a src to destination buffer @a dst.