Libmib Allocated String Functions
Background - Usage - Issues - Example Uses - Get the source
Background
Libmib astrings implement a fast, efficient "limitless" string. Use astrings in place of fixed length string buffers, which are a common area of software defects causing operational or security failure.
Libmib Design for Reuse
Goals of the astring memory management subroutines
- Be compatible with malloc(), realloc() and free() calls.
- Be compatible with existing string library calls.
- Try to prevent copying reallocs.
- Minimize storage "overhead."
- Portability. Do not rely on non-standard functions to manage memory.
Usage
C and C++ sources which #include "libmib/astring.h" can
- Use the astring equivalents for strcpy(), strncpy(), strcat(), or strncat(). They are declared as follows:
char *astrcpy(char **ppasz,const char *pSrc);
char *astrn0cpy(char **ppasz,const char *pSrc,int n);
/* NOTE: astrn0cpy Always stores the ending \0 */
- Take advantage of the "astring-enhanced" sprintf and fgets functions.
int avsprintf(char **ppasz, const char *format,va_list ap);
int asprintf(char **ppasz, const char *format,...);
char *afgets(char **ppasz,FILE *f);
int afgettoch(char **ppasz,FILE *f, char chStop)
/* Reads up to and including the next chStop character,
storing a \0 afterwards. Returns number of characters read. */
Details, important reminders, and examples are available at libmib astring usage.
String handling Comparison illustrates a number of common ways (some safe, some not) of handling strings in C. libmib astring functions make safe string handling simple.
libmib astring usage
There are just a few simple points to remember when creating, using, and destroying astrings.
astring advanced usage
Using astrensure() to write your own limitless string functions.
Example: an "fgrep-like" filter using astrings easily handles unlimited line lengths in a small amount of code.
Get the Source
Terms of Use: Free for commercial and non-commercial use under the libmib license
In your synclibmib.sh script, use
httpsync @http://www.mibsoftware.com/cgi/synclibmib.cgi?set=astring
to synchronize to the following packing list. (NOTE: These files #include <libmib/local.h>
, which can be created as an empty file when no local libmib configurations are necessary.)
#-#httpsync 101 Packing List for httpsync 1.01-1.02
# Visit the httpsync home page: http://www.mibsoftware.com/httpsync/
R/libmib/astring.lst
./libmib/astring.h 5923 Mon, 14 Dec 1998 21:18:28 GMT 644
./libmib/compat.h 7327 Thu, 06 Jan 2000 15:38:46 GMT 644
./parse/astring.c 18901 Wed, 15 Dec 1999 14:40:36 GMT 644
./parse/asprintf.c 16808 Tue, 22 Dec 1998 21:34:28 GMT 644
Up to: Libmib: Character String Processing
Up to: Libmib
This Libmib documentation may not be distributed.
Copyright 1998, Forrest J. Cavalier III
Mib Software
High Reuse Software Development