Subversion Repositories HelenOS

Rev

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

Rev 4280 Rev 4281
Line 33... Line 33...
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <string.h>
36
#include <string.h>
37
#include <stdlib.h>
37
#include <stdlib.h>
-
 
38
#include <assert.h>
38
#include <limits.h>
39
#include <limits.h>
39
#include <ctype.h>
40
#include <ctype.h>
40
#include <malloc.h>
41
#include <malloc.h>
41
#include <errno.h>
42
#include <errno.h>
42
#include <align.h>
43
#include <align.h>
Line 468... Line 469...
468
 * No more than @a size bytes are written. If the size of the output buffer
469
 * No more than @a size bytes are written. If the size of the output buffer
469
 * is at least one byte, the output string will always be well-formed, i.e.
470
 * is at least one byte, the output string will always be well-formed, i.e.
470
 * null-terminated and containing only complete characters.
471
 * null-terminated and containing only complete characters.
471
 *
472
 *
472
 * @param dst   Destination buffer.
473
 * @param dst   Destination buffer.
473
 * @param count Size of the destination buffer.
474
 * @param count Size of the destination buffer (must be > 0).
474
 * @param src   Source string.
475
 * @param src   Source string.
475
 */
476
 */
476
void str_cpy(char *dest, size_t size, const char *src)
477
void str_cpy(char *dest, size_t size, const char *src)
477
{
478
{
478
    wchar_t ch;
479
    wchar_t ch;
479
    size_t src_off;
480
    size_t src_off;
480
    size_t dest_off;
481
    size_t dest_off;
481
 
482
 
482
    /* No space for the NULL-terminator in the buffer. */
483
    /* There must be space for a null terminator in the buffer. */
483
    if (size == 0)
484
    assert(size > 0);
484
        return;
-
 
485
   
485
   
486
    src_off = 0;
486
    src_off = 0;
487
    dest_off = 0;
487
    dest_off = 0;
488
 
488
 
489
    while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
489
    while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
Line 494... Line 494...
494
    dest[dest_off] = '\0';
494
    dest[dest_off] = '\0';
495
}
495
}
496
 
496
 
497
/** Copy size-limited substring.
497
/** Copy size-limited substring.
498
 *
498
 *
499
 * Copy source string @a src to destination buffer @a dest.
499
 * Copy prefix of string @a src of max. size @a size to destination buffer
500
 * No more than @a size bytes are written. If the size of the output buffer
500
 * @a dest. No more than @a size bytes are written. The output string will
501
 * is at least one byte, the output string will always be well-formed, i.e.
501
 * always be well-formed, i.e. null-terminated and containing only complete
502
 * null-terminated and containing only complete characters.
502
 * characters.
503
 *
503
 *
504
 * No more than @a n bytes are read from the input string, so it does not
504
 * No more than @a n bytes are read from the input string, so it does not
505
 * have to be null-terminated.
505
 * have to be null-terminated.
506
 *
506
 *
507
 * @param dst   Destination buffer.
507
 * @param dst   Destination buffer.
508
 * @param count Size of the destination buffer.
508
 * @param count Size of the destination buffer (must be > 0).
509
 * @param src   Source string.
509
 * @param src   Source string.
-
 
510
 * @param n Maximum number of bytes to read from @a src.
510
 */
511
 */
511
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
512
void str_ncpy(char *dest, size_t size, const char *src, size_t n)
512
{
513
{
513
    wchar_t ch;
514
    wchar_t ch;
514
    size_t src_off;
515
    size_t src_off;
515
    size_t dest_off;
516
    size_t dest_off;
516
 
517
 
517
    /* No space for the null terminator in the buffer. */
518
    /* There must be space for a null terminator in the buffer. */
518
    if (size == 0)
519
    assert(size > 0);
519
        return;
-
 
520
   
520
   
521
    src_off = 0;
521
    src_off = 0;
522
    dest_off = 0;
522
    dest_off = 0;
523
 
523
 
524
    while ((ch = str_decode(src, &src_off, n)) != 0) {
524
    while ((ch = str_decode(src, &src_off, n)) != 0) {