Home
Highly Reusable Software By activity User Interface Text Strings Math Processing
Stored Data
Communications
Hard World File System
|
#License - #Source code - #Example Use -
#include <librock/astring.h> int librock_astrprintf( char librock_PTR * librock_PTR *ppasz, const char *format, ...); int librock_vastrprintf( char librock_PTR * librock_PTR *ppasz, const char *format, va_list ap);
If your platform has vasprintf(), then #define librock_aprintf_USE_vasprintf when compiling for the most efficient implementation. (This can be done in <librock/target/local.h>)
Otherwise, this uses tmpfile() and vfprintf() when the format string contains a field width specifier or any format other than %%, %d, %u and %s. Using tmpfile() and reading the result has significant performance penalties, but this use avoids buffer overruns in a portable way.
Since this calls the underlying (vf)printf(), you get the features and liabilities of that implementation. James Antill has a comparison of implementations and caveats at http://www.and.org/vstr/printf_comparison.html
Typical use is
char *asz = 0; librock_astrprintf(&asz,"This is a test %s\n",pszLongString); . . . librock_astrfree(&asz);
librock_astrensure() vasprintf() memcpy() //#ifdef librock_aprintf_USE_vasprintf vfprintf() sprintf() tmpfile() ftell() rewind() fread() fclose() //#ifndef librock_aprintf_USE_vasprintf
Copyright 1998-2003 Forrest J. Cavalier III, http://www.mibsoftware.com Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45
Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)
Want to help? We welcome comments, patches. -- Need help? Request paid support.