Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

sfsnprintfappend.c

Go to the documentation of this file.
00001 /*
00002 *
00003 *  sfsnprintfappend.h
00004 *
00005 *  snprintf that appends to destination buffer
00006 *
00007 *  Copyright (C) 2004 Sourcefire, Inc.
00008 *
00009 *  Author: Steven Sturges
00010 *
00011 */
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <stdarg.h>
00019 #include <unistd.h>
00020 #include <string.h>
00021 
00022 /****************************************************************************
00023  *
00024  * Function: sfsnprintfappend
00025  *
00026  * Purpose: snprintf that appends to destination buffer
00027  *
00028  *          Appends the snprintf format string and arguments to dest
00029  *          without going beyond dsize bounds.  Assumes dest has
00030  *          been properly allocated, and is of dsize in length.
00031  *
00032  * Arguments: dest      ==> pointer to string buffer to append to
00033  *            dsize     ==> size of buffer dest
00034  *            format    ==> snprintf format string
00035  *            ...       ==> arguments for printf
00036  *
00037  * Returns: number of characters added to the buffer
00038  *
00039  ****************************************************************************/
00040 int sfsnprintfappend(char *dest, int dsize, const char *format, ...)
00041 {
00042     int currLen, appendLen;
00043     va_list ap;
00044 
00045     if (!dest || dsize == 0)
00046         return -1;
00047 
00048     currLen = strlen(dest);
00049 
00050     va_start(ap, format);
00051     appendLen = vsnprintf(dest+currLen, dsize-currLen, format, ap);
00052     va_end(ap);
00053 
00054     return appendLen;
00055 }
00056 

Generated on Sun May 14 14:51:18 2006 by  doxygen 1.4.2