1 /* $OpenBSD: snprintf.c,v 1.16 2009/10/22 01:23:16 guenther Exp $ */
3 * SPDX-License-Identifier: BSD-3-Clause
5 * Copyright (C) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
18 #include "ust-snprintf.h"
22 int ust_safe_vsnprintf(char *str
, size_t n
, const char *fmt
, va_list ap
)
25 char dummy
[DUMMY_LEN
];
27 struct __lttng_ust_sfileext fext
;
29 /* While snprintf(3) specifies size_t stdio uses an int internally */
32 /* Stdio internals do not deal correctly with zero length buffer */
37 _FILEEXT_SETUP(&f
, &fext
);
39 f
._flags
= __SWR
| __SSTR
;
40 f
._bf
._base
= f
._p
= (unsigned char *)str
;
41 f
._bf
._size
= f
._w
= n
- 1;
42 ret
= ust_safe_vfprintf(&f
, fmt
, ap
);
47 int ust_safe_snprintf(char *str
, size_t n
, const char *fmt
, ...)
53 ret
= ust_safe_vsnprintf(str
, n
, fmt
, ap
);