/* ================================================================================ RPL/2 (R) version 4.1.1 Copyright (C) 1989-2011 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl.h" int valsprintf(unsigned char **strp, const char *fmt, va_list ap) { size_t bs; size_t s; unsigned char *b = NULL; va_list cap; for(bs = 1024;; bs *= 2) { va_copy(cap, ap); if (b != NULL) { free(b); } if ((b = malloc(sizeof(*b) * bs)) == NULL) { return -1; } if (((int) (s = vsnprintf(b, bs, fmt, cap))) < 0) { free(b); return -1; } if (s < bs) { break; } } if (((*strp) = realloc(b, ((s = strlen(b)) + 1) * sizeof(*b))) == NULL) { free(b); return -1; } return s; } int alsprintf(unsigned char **strp, const char *fmt, ...) { int done; va_list arg; va_start(arg, fmt); done = valsprintf(strp, fmt, arg); va_end(arg); return(done); } // vim: ts=4