Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_vastrprintf - printf into an allocated string.
#License - #Source code - #Example Use -

SYNOPSIS

#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);

DESCRIPTION

Operates as the ANSI standard fprintf() and vfprintf(), but the output is placed into a buffer large enough to hold the output, obtained using librock_astrensure()

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);

USES

  librock_astrensure()
  vasprintf() memcpy() //#ifdef librock_aprintf_USE_vasprintf

  vfprintf() sprintf() tmpfile() ftell() rewind() fread() fclose() //#ifndef librock_aprintf_USE_vasprintf



LICENSE

  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

Source Code

./text/aprintf.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

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.