blob: 84e01f08d38e8a398074675f8c0430d26eca70e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*******************************************************************/
/* slibtool: a strong libtool implementation, written in C */
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "slibtool_snprintf_impl.h"
#include "slibtool_visibility_impl.h"
/*****************************************************************/
/* snprintf() wrapper that simplifies usage via the following: */
/* */
/* (1) fail (return a negative result) in case the buffer is */
/* not sufficiently large for the formatted string plus */
/* the terminating null character. */
/* */
/**********************************************************/
slbt_hidden int slbt_snprintf(char * buf, size_t buflen, const char * fmt, ...)
{
va_list ap;
size_t nbytes;
va_start(ap,fmt);
nbytes = vsnprintf(buf,buflen,fmt,ap);
va_end(ap);
if (nbytes >= buflen)
return -1;
return nbytes;
}
|