summaryrefslogtreecommitdiff
path: root/lib/nowarn_snprintf.h
blob: 81a6d10849c7edd49f585a027db6399d305cd94f (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
#ifndef _NOWARN_SNPRINTF_H_
#define _NOWARN_SNPRINTF_H_

#include <stdio.h>
#include <stdarg.h>

static inline int nowarn_snprintf(char *str, size_t size, const char *format,
				  ...)
{
	va_list args;
	int res;

	va_start(args, format);
#if __GNUC__ -0 >= 8
#pragma GCC diagnostic push "-Wformat-truncation"
#pragma GCC diagnostic ignored "-Wformat-truncation"
#endif
	res = vsnprintf(str, size, format, args);
#if __GNUC__ -0 >= 8
#pragma GCC diagnostic pop "-Wformat-truncation"
#endif
	va_end(args);

	return res;
}

#endif