Subversion Repositories HelenOS

Rev

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

Rev 4266 Rev 4268
Line 460... Line 460...
460
 
460
 
461
    return 0;
461
    return 0;
462
 
462
 
463
}
463
}
464
 
464
 
465
/** Copy NULL-terminated string.
465
/** Copy string.
466
 *
466
 *
467
 * Copy source string @a src to destination buffer @a dst.
467
 * Copy source string @a src to destination buffer @a dest.
468
 * No more than @a size bytes are written. NULL-terminator is always
468
 * No more than @a size bytes are written. If the size of the output buffer
469
 * written after the last succesfully copied character (i.e. if the
469
 * is at least one byte, the output string will always be well-formed, i.e.
470
 * destination buffer is has at least 1 byte, it will be always
470
 * null-terminated and containing only complete characters.
471
 * NULL-terminated).
-
 
472
 *
471
 *
473
 * @param src   Source string.
-
 
474
 * @param dst   Destination buffer.
472
 * @param dst   Destination buffer.
475
 * @param count Size of the destination buffer.
473
 * @param count Size of the destination buffer.
476
 *
474
 * @param src   Source string.
477
 */
475
 */
478
void str_ncpy(char *dst, const char *src, size_t size)
476
void str_cpy(char *dest, size_t size, const char *src)
479
{
477
{
-
 
478
    wchar_t ch;
-
 
479
    size_t src_off;
-
 
480
    size_t dest_off;
-
 
481
 
480
    /* No space for the NULL-terminator in the buffer */
482
    /* No space for the NULL-terminator in the buffer. */
481
    if (size == 0)
483
    if (size == 0)
482
        return;
484
        return;
483
   
485
   
-
 
486
    src_off = 0;
-
 
487
    dest_off = 0;
-
 
488
 
-
 
489
    while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
-
 
490
        if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-
 
491
            break;
-
 
492
    }
-
 
493
 
-
 
494
    dest[dest_off] = '\0';
-
 
495
}
-
 
496
 
-
 
497
/** Copy size-limited substring.
-
 
498
 *
-
 
499
 * Copy source string @a src to destination buffer @a dest.
-
 
500
 * No more than @a size bytes are written. If the size of the output buffer
-
 
501
 * is at least one byte, the output string will always be well-formed, i.e.
-
 
502
 * null-terminated and containing only complete characters.
-
 
503
 *
-
 
504
 * No more than @a n bytes are read from the input string, so it does not
-
 
505
 * have to be null-terminated.
-
 
506
 *
-
 
507
 * @param dst   Destination buffer.
-
 
508
 * @param count Size of the destination buffer.
-
 
509
 * @param src   Source string.
-
 
510
 */
-
 
511
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
-
 
512
{
484
    wchar_t ch;
513
    wchar_t ch;
485
    size_t str_off = 0;
514
    size_t src_off;
486
    size_t dst_off = 0;
515
    size_t dest_off;
-
 
516
 
-
 
517
    /* No space for the null terminator in the buffer. */
-
 
518
    if (size == 0)
-
 
519
        return;
487
   
520
   
-
 
521
    src_off = 0;
-
 
522
    dest_off = 0;
-
 
523
 
488
    while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
524
    while ((ch = str_decode(src, &src_off, n)) != 0) {
489
        if (chr_encode(ch, dst, &dst_off, size) != EOK)
525
        if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
490
            break;
526
            break;
491
    }
527
    }
492
   
528
 
493
    if (dst_off >= size)
-
 
494
        dst[size - 1] = 0;
-
 
495
    else
-
 
496
        dst[dst_off] = 0;
529
    dest[dest_off] = '\0';
497
}
530
}
498
 
531
 
499
/** Copy NULL-terminated wide string to string
532
/** Copy NULL-terminated wide string to string
500
 *
533
 *
501
 * Copy source wide string @a src to destination buffer @a dst.
534
 * Copy source wide string @a src to destination buffer @a dst.
Line 796... Line 829...
796
    number = _strtoul(nptr, endptr, base, &sgn);
829
    number = _strtoul(nptr, endptr, base, &sgn);
797
 
830
 
798
    return (sgn ? -number : number);
831
    return (sgn ? -number : number);
799
}
832
}
800
 
833
 
801
char *strcpy(char *dest, const char *src)
-
 
802
{
-
 
803
    char *orig = dest;
-
 
804
   
-
 
805
    while ((*(dest++) = *(src++)))
-
 
806
        ;
-
 
807
    return orig;
-
 
808
}
-
 
809
 
-
 
810
char *strcat(char *dest, const char *src)
834
char *strcat(char *dest, const char *src)
811
{
835
{
812
    char *orig = dest;
836
    char *orig = dest;
813
    while (*dest++)
837
    while (*dest++)
814
        ;
838
        ;