Subversion Repositories HelenOS-historic

Rev

Rev 1288 | Rev 1605 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1288 Rev 1604
Line 48... Line 48...
48
 * @param data structure with destination string, counter of used space and total string size.
48
 * @param data structure with destination string, counter of used space and total string size.
49
 * @return number of characters to print (not characters really printed!)
49
 * @return number of characters to print (not characters really printed!)
50
 */
50
 */
51
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
51
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
52
{
52
{
53
    size_t i,j;
53
    size_t i;
54
    i = data->size - data->len;
54
    i = data->size - data->len;
55
    j = count;
-
 
56
 
55
 
57
    if (i > 0) {
56
    if ((count == 0) || (i == 0)) {
58
        if (i <= j) {
57
        return 0;
-
 
58
    }
-
 
59
   
59
            if (i == 1) {
60
    if (i == 1) {
60
                /* We have only one free byte left in buffer => write there trailing zero */
61
        /* We have only one free byte left in buffer => write there trailing zero */
61
                data->string[data->size - 1] = 0;
62
        data->string[data->size - 1] = 0;
62
                data->len = data->size;
63
        data->len = data->size;
63
            } else {
64
        return 1;
-
 
65
    }
-
 
66
   
-
 
67
    if (i <= count) {
64
                /* We have not enought space for whole string with the trailing zero => print only a part of string */
68
        /* We have not enought space for whole string with the trailing zero => print only a part of string */
65
                memcpy((void *)(data->string + data->len), (void *)str, i - 1);
69
            memcpy((void *)(data->string + data->len), (void *)str, i - 1);
66
                data->string[data->size - 1] = 0;
70
            data->string[data->size - 1] = 0;
67
                data->len = data->size;
71
            data->len = data->size;
-
 
72
            return i;
68
            }
73
    }
69
        } else {
74
   
70
            /* Buffer is big enought to print whole string */
75
    /* Buffer is big enought to print whole string */
71
            memcpy((void *)(data->string + data->len), (void *)str, j);
76
    memcpy((void *)(data->string + data->len), (void *)str, count);
72
            data->len += j;
77
    data->len += count;
73
            /* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
78
    /* Put trailing zero at end, but not count it into data->len so it could be rewritten next time */
74
            data->string[data->len] = 0;
79
    data->string[data->len] = 0;
75
        }
-
 
76
    }
-
 
77
   
80
 
78
    return count;  
81
    return count;  
79
}
82
}
80
 
83
 
81
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
84
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)