Subversion Repositories HelenOS

Rev

Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2307
Line 41... Line 41...
41
    size_t size; /* total space for string */
41
    size_t size; /* total space for string */
42
    size_t len; /* count of currently used characters */
42
    size_t len; /* count of currently used characters */
43
    char *string; /* destination string */
43
    char *string; /* destination string */
44
};
44
};
45
 
45
 
46
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data);
-
 
47
 
-
 
48
/** Write string to given buffer.
46
/** Write string to given buffer.
49
 * Write at most data->size characters including trailing zero. According to C99 has snprintf to return number
47
 * Write at most data->size characters including trailing zero. According to C99 has snprintf to return number
50
 * of characters that would have been written if enough space had been available. Hence the return value is not
48
 * of characters that would have been written if enough space had been available. Hence the return value is not
51
 * number of really printed characters but size of input string. Number of really used characters
49
 * number of really printed characters but size of input string. Number of really used characters
52
 * is stored in data->len.
50
 * is stored in data->len.
53
 * @param str source string to print
51
 * @param str source string to print
54
 * @param count size of source string
52
 * @param count size of source string
55
 * @param data structure with destination string, counter of used space and total string size.
53
 * @param data structure with destination string, counter of used space and total string size.
56
 * @return number of characters to print (not characters really printed!)
54
 * @return number of characters to print (not characters really printed!)
57
 */
55
 */
58
int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
56
static int vsnprintf_write(const char *str, size_t count, struct vsnprintf_data *data)
59
{
57
{
60
    size_t i;
58
    size_t i;
61
    i = data->size - data->len;
59
    i = data->size - data->len;
62
 
60
 
63
    if (i == 0) {
61
    if (i == 0) {
Line 95... Line 93...
95
 * \see For more details about format string see printf_core.
93
 * \see For more details about format string see printf_core.
96
 */
94
 */
97
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
95
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
98
{
96
{
99
    struct vsnprintf_data data = {size, 0, str};
97
    struct vsnprintf_data data = {size, 0, str};
100
    struct printf_spec ps = {(int(*)(void *, size_t, void *))vsnprintf_write, &data};
98
    struct printf_spec ps = {(int(*)(void *, size_t, void *)) vsnprintf_write, &data};
101
 
99
 
102
    /* Print 0 at end of string - fix the case that nothing will be printed */
100
    /* Print 0 at end of string - fix the case that nothing will be printed */
103
    if (size > 0)
101
    if (size > 0)
104
        str[0] = 0;
102
        str[0] = 0;
105
   
103