summaryrefslogtreecommitdiff
path: root/stdio.c
blob: 89bd677f9998fc8c4f9202355303c7a7d6c98580 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>

size_t __fread_chk(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
	assert(ptr != NULL);
	assert(stream != NULL);
	return fread(ptr, size, nmemb, stream);
}

int __printf_chk(int flag, const char *format, ...)
{
	va_list argp;
	int result;

	if(flag > 0)
	{
		assert(format != NULL);
	}

	va_start(argp, format);
	result = vprintf(format, argp);
	va_end(argp);

	return result;
}

int __fprintf_chk(FILE *stream, int flag, const char *format, ...)
{
	va_list argp;
	int result;

	if(flag > 0)
	{
		assert(stream != NULL);
		assert(format != NULL);
	}

	va_start(argp, format);
	result = vfprintf(stream, format, argp);
	va_end(argp);

	return result;
}

int __sprintf_chk(char *str, int flag, size_t strlen, const char *format, ...)
{
	va_list argp;
	int result;

	assert(strlen > 0);

	va_start(argp, format);
	result = vsnprintf(str, strlen, format, argp);
	va_end(argp);

	return result;
}

int __snprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, ...)
{
	va_list argp;
	int result;

	if(flag > 0)
	{
		assert(format != NULL);
	}
	// must always be done per LFS
	assert(size <= strlen);

	va_start(argp, format);
	result = vsnprintf(str, size, format, argp);
	va_end(argp);

	return result;
}

int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen, const wchar_t *format, ...)
{
	va_list argp;
	int result;

	if(flag > 0)
	{
		assert(format != NULL);
	}
	// must always be done per LFS
	assert(maxlen <= wcslen);

	va_start(argp, format);
	result = vswprintf(wcs, maxlen, format, argp);
	va_end(argp);

	return result;
}

int __vasprintf_chk(char **strp, int flag, const char *fmt, va_list ap)
{
	if(flag > 0)
	{
		assert(strp != NULL);
		assert(fmt != NULL);
	}
	return vasprintf(strp, fmt, ap);
}

int __vfprintf_chk(FILE *stream, int flag, const char *format, va_list ap)
{
	if(flag > 0)
	{
		assert(stream != NULL);
		assert(format != NULL);
	}
	return vfprintf(stream, format, ap);
}

int __vsnprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, va_list ap)
{
	if(flag > 0)
	{
		assert(format != NULL);
	}
	// must always be done per LFS
	assert(size <= strlen);
	return vsnprintf(str, size, format, ap);
}