Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/asprintf.c

    ra9763c6 r9d58539  
    5050}
    5151
    52 int vprintf_size(const char *fmt, va_list args)
    53 {
    54         printf_spec_t ps = {
    55                 asprintf_str_write,
    56                 asprintf_wstr_write,
    57                 NULL
    58         };
    59        
    60         return printf_core(fmt, &ps, args);
    61 }
    62 
    63 int printf_size(const char *fmt, ...)
    64 {
    65         va_list args;
    66         va_start(args, fmt);
    67         int ret = vprintf_size(fmt, args);
    68         va_end(args);
    69        
    70         return ret;
    71 }
    72 
    73 /** Allocate and print to string.
    74  *
    75  * @param strp Address of the pointer where to store the address of
    76  *             the newly allocated string.
    77  * @fmt        Format string.
    78  * @args       Variable argument list
    79  *
    80  * @return Number of characters printed or a negative error code.
    81  *
    82  */
    83 int vasprintf(char **strp, const char *fmt, va_list args)
    84 {
    85         va_list args2;
    86         va_copy(args2, args);
    87         int ret = vprintf_size(fmt, args2);
    88         va_end(args2);
    89        
    90         if (ret > 0) {
    91                 *strp = malloc(STR_BOUNDS(ret) + 1);
    92                 if (*strp == NULL)
    93                         return -1;
    94                
    95                 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
    96         }
    97        
    98         return ret;
    99 }
    100 
    10152/** Allocate and print to string.
    10253 *
     
    11061int asprintf(char **strp, const char *fmt, ...)
    11162{
     63        printf_spec_t ps = {
     64                asprintf_str_write,
     65                asprintf_wstr_write,
     66                NULL
     67        };
     68       
    11269        va_list args;
    11370        va_start(args, fmt);
    114         int ret = vasprintf(strp, fmt, args);
     71       
     72        int ret = printf_core(fmt, &ps, args);
    11573        va_end(args);
     74       
     75        if (ret > 0) {
     76                *strp = malloc(STR_BOUNDS(ret) + 1);
     77                if (*strp == NULL)
     78                        return -1;
     79               
     80                va_start(args, fmt);
     81                vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
     82                va_end(args);
     83        }
    11684       
    11785        return ret;
Note: See TracChangeset for help on using the changeset viewer.