File: snprintf.c

package info (click to toggle)
ust 2.14.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,368 kB
  • sloc: xml: 78,798; ansic: 47,114; sh: 5,806; java: 2,202; makefile: 1,833; python: 727; cpp: 384
file content (26 lines) | stat: -rw-r--r-- 568 bytes parent folder | download | duplicates (3)
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
/*
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * Copyright (C) 2009 Pierre-Marc Fournier
 */

#include <stdio.h>
#include <string.h>
#include "common/safe-snprintf.h"

#include "tap.h"

int main(void)
{
	char buf[100];
	const char expected_str[] = "header 9999, hello, 005, '    9'";
	const char test_fmt_str[] = "header %d, %s, %03d, '%*d'";

	plan_tests(1);

	ust_safe_snprintf(buf, 99, test_fmt_str, 9999, "hello", 5, 5, 9);

	ok(strcmp(buf, expected_str) == 0, "Got expected output string with format string \"%s\"", test_fmt_str);

	return exit_status();
}