Blame src/internal/slibtool_snprintf_impl.c

19022e
/*******************************************************************/
19022e
/*  slibtool: a skinny libtool implementation, written in C        */
19022e
/*  Copyright (C) 2016--2021  SysDeer Technologies, LLC            */
19022e
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
19022e
/*******************************************************************/
19022e
19022e
#include <stdio.h>
19022e
#include <stdarg.h>
19022e
#include <stdlib.h>
19022e
#include <unistd.h>
19022e
#include <errno.h>
19022e
19022e
#include "slibtool_snprintf_impl.h"
19022e
19022e
19022e
/*****************************************************************/
19022e
/* snprintf() wrapper that simplifies usage via the following:  */
19022e
/*                                                             */
19022e
/* (1) fail (return a negative result) in case the buffer is  */
19022e
/*     not sufficiently large for the formatted string plus  */
19022e
/*     the terminating null character.                      */
19022e
/*                                                         */
19022e
/**********************************************************/
19022e
19022e
19022e
int slbt_snprintf(char * buf, size_t buflen, const char * fmt, ...)
19022e
{
19022e
	va_list	ap;
19022e
	size_t  nbytes;
19022e
19022e
	va_start(ap,fmt);
19022e
	nbytes = vsnprintf(buf,buflen,fmt,ap);
19022e
	va_end(ap);
19022e
19022e
	if (nbytes >= buflen)
19022e
		return -1;
19022e
19022e
	return nbytes;
19022e
}