"Fossies" - the Fresh Open Source Software Archive

Member "duff-0.5.2/src/duffstring.c" (10 Apr 2011, 1712 Bytes) of package /linux/privat/old/duff-0.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * duff - Duplicate file finder
    3  * Copyright (c) 2005 Camilla Berglund <elmindreda@elmindreda.org>
    4  *
    5  * This software is provided 'as-is', without any express or implied
    6  * warranty. In no event will the authors be held liable for any
    7  * damages arising from the use of this software.
    8  *
    9  * Permission is granted to anyone to use this software for any
   10  * purpose, including commercial applications, and to alter it and
   11  * redistribute it freely, subject to the following restrictions:
   12  *
   13  *  1. The origin of this software must not be misrepresented; you
   14  *     must not claim that you wrote the original software. If you use
   15  *     this software in a product, an acknowledgment in the product
   16  *     documentation would be appreciated but is not required.
   17  *
   18  *  2. Altered source versions must be plainly marked as such, and
   19  *     must not be misrepresented as being the original software.
   20  *
   21  *  3. This notice may not be removed or altered from any source
   22  *     distribution.
   23  */
   24 
   25 #if HAVE_CONFIG_H
   26 #include "config.h"
   27 #endif
   28 
   29 #if HAVE_STDARG_H
   30 #include <stdarg.h>
   31 #endif
   32 
   33 #if HAVE_STRING_H
   34 #include <string.h>
   35 #endif
   36 
   37 #if !HAVE_VASPRINTF
   38 
   39 int vasprintf(char** result, const char* format, va_list vl)
   40 {
   41   char buffer[8192];
   42 
   43   if (vsnprintf(buffer, sizeof(buffer), format, vl) < 0)
   44     buffer[sizeof(buffer) - 1] = '\0';
   45 
   46   size_t length = strlen(buffer);
   47   *result = (char*) malloc(length + 1);
   48   strcpy(*result, buffer);
   49 
   50   return length;
   51 }
   52 
   53 #endif /*HAVE_VASPRINTF*/
   54 
   55 #if !HAVE_ASPRINTF
   56 
   57 int asprintf(char** result, const char* format, ...)
   58 {
   59   va_list vl;
   60   int length;
   61 
   62   va_start(vl, format);
   63   length = vasprintf(result, format, vl);
   64   va_end(vl);
   65 
   66   return length;
   67 }
   68 
   69 #endif /*HAVE_ASPRINTF*/
   70