1570af302Sopenharmony_ci// commit: 5cbd76c6b05b381f269e0e204e10690d69f1d6ea 2011-02-16
2570af302Sopenharmony_ci// commit: bdc9ed15651b70e89f83c5a9f7d1ba349e624503 2011-02-20
3570af302Sopenharmony_ci// printf %n fmt
4570af302Sopenharmony_ci#include <stdint.h>
5570af302Sopenharmony_ci#include <stdio.h>
6570af302Sopenharmony_ci#include "test.h"
7570af302Sopenharmony_ci
8570af302Sopenharmony_ci#define T(n,nfmt,fmt) do { \
9570af302Sopenharmony_ci	if ((ret = sprintf(buf, "%256d%d" nfmt "%d", 1, 2, &n, 3)) != 258) \
10570af302Sopenharmony_ci		t_error("expexted sprintf to write 258 chars, got %d\n", ret); \
11570af302Sopenharmony_ci	if (n != 257) \
12570af302Sopenharmony_ci		t_error("%%n format failed: wanted 257, got " fmt "\n", n); \
13570af302Sopenharmony_ci} while(0)
14570af302Sopenharmony_ci
15570af302Sopenharmony_ciint main(void)
16570af302Sopenharmony_ci{
17570af302Sopenharmony_ci	char buf[1024];
18570af302Sopenharmony_ci	int ret;
19570af302Sopenharmony_ci	int i;
20570af302Sopenharmony_ci	long l;
21570af302Sopenharmony_ci	long long ll;
22570af302Sopenharmony_ci	short h;
23570af302Sopenharmony_ci	size_t z;
24570af302Sopenharmony_ci	uintmax_t j;
25570af302Sopenharmony_ci
26570af302Sopenharmony_ci	T(i,    "%n",   "%d");
27570af302Sopenharmony_ci	T(l,   "%ln",  "%ld");
28570af302Sopenharmony_ci	T(ll, "%lln", "%lld");
29570af302Sopenharmony_ci	T(h,   "%hn",   "%d");
30570af302Sopenharmony_ci	T(z,   "%zn",  "%zd");
31570af302Sopenharmony_ci	T(j,   "%jn",  "%jd");
32570af302Sopenharmony_ci
33570af302Sopenharmony_ci	return t_status;
34570af302Sopenharmony_ci}
35