ucx/utils.h

changeset 142
ee8cb27d8b8e
parent 140
15f871f50bfd
child 144
b6dcc9d112eb
     1.1 --- a/ucx/utils.h	Tue Aug 13 14:20:12 2013 +0200
     1.2 +++ b/ucx/utils.h	Wed Aug 14 15:22:35 2013 +0200
     1.3 @@ -43,8 +43,11 @@
     1.4  #endif
     1.5  
     1.6  #include "ucx.h"
     1.7 +#include "string.h"
     1.8 +#include "allocator.h"
     1.9  #include <stdint.h>
    1.10  #include <string.h>
    1.11 +#include <stdarg.h>
    1.12  
    1.13  /**
    1.14   * Copies a string.
    1.15 @@ -133,7 +136,6 @@
    1.16   * @return -1, if *i1 is less than *i2, 0 if both are equal,
    1.17   * 1 if *i1 is greater than *i2
    1.18   */
    1.19 -
    1.20  int ucx_intcmp(void *i1, void *i2, void *data);
    1.21  
    1.22  /**
    1.23 @@ -155,7 +157,6 @@
    1.24   * @return -1, if *d1 is less than *d2, 0 if both are equal,
    1.25   * 1 if *d1 is greater than *d2
    1.26   */
    1.27 -
    1.28  int ucx_doublecmp(void *d1, void *d2, void *data);
    1.29  
    1.30  /**
    1.31 @@ -177,6 +178,57 @@
    1.32   */
    1.33  int ucx_memcmp(void *ptr1, void *ptr2, void *n);
    1.34  
    1.35 +/**
    1.36 + * A printf like function which writes the output to a stream using a write
    1.37 + * function.
    1.38 + * @param stream the stream where to write the data
    1.39 + * @param wfc the write function for the stream
    1.40 + * @param fmt format string
    1.41 + * @param ... additional arguments
    1.42 + * @return the total number of bytes written
    1.43 + */
    1.44 +int ucx_fprintf(void *stream, write_func wfc, const char *fmt, ...);
    1.45 +
    1.46 +/**
    1.47 + * Same as ucx_fprintf() but with an argument list instead of variadic
    1.48 + * arguments.
    1.49 + * @param stream the stream where to write the data
    1.50 + * @param wfc the write function for the stream
    1.51 + * @param fmt format string
    1.52 + * @param ap argument list
    1.53 + * @return the total number of bytes written
    1.54 + * @see ucx_fprintf()
    1.55 + */
    1.56 +int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap);
    1.57 +
    1.58 +/**
    1.59 + * A printf lile function which stores the result in a newly created string.
    1.60 + * 
    1.61 + * The sstr_t data is allocated with the allocators ucx_allocator_malloc
    1.62 + * function. So it is implementation depended, whether the returned
    1.63 + * sstr_t.ptr pointer must be passed to the allocators ucx_allocator_free
    1.64 + * function manually.
    1.65 + * 
    1.66 + * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>-
    1.67 + * terminated.
    1.68 + * 
    1.69 + * @param allocator a valid instance of an UcxAllocator
    1.70 + * @param fmt format string
    1.71 + * @param ... additional arguments
    1.72 + * @return a new string
    1.73 + */
    1.74 +sstr_t ucx_asprintf(UcxAllocator *allocator, const char *fmt, ...);
    1.75 +
    1.76 +/**
    1.77 + * Same as ucx_asprintf() but with an argument list instead of variadic
    1.78 + * arguments.
    1.79 + * @param allocator a valid instance of an UcxAllocator
    1.80 + * @param fmt format string
    1.81 + * @param ap argument list
    1.82 + * @return a new string
    1.83 + */
    1.84 +sstr_t ucx_vasprintf(UcxAllocator *allocator, const char *fmt, va_list ap);
    1.85 +
    1.86  #ifdef	__cplusplus
    1.87  }
    1.88  #endif

mercurial