File: t_strappend.c

package info (click to toggle)
samba 2%3A3.2.5-4lenny15
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 124,704 kB
  • ctags: 69,181
  • sloc: ansic: 564,153; xml: 219,271; sh: 11,039; perl: 4,458; makefile: 4,301; python: 1,975; cpp: 1,224; exp: 1,147; yacc: 881; awk: 557; csh: 58; sed: 45
file content (45 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (6)
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
/*
 * Copyright (C) 2005 by Volker Lendecke
 *
 * Test harness for sprintf_append
 */

#include "includes.h"
#include <assert.h>

int main(int argc, char *argv[])
{
	TALLOC_CTX *mem_ctx;
	char *string = NULL;
	int len = 0;
	int bufsize = 4;
	int i;

	mem_ctx = talloc_init("t_strappend");
	if (mem_ctx == NULL) {
		fprintf(stderr, "talloc_init failed\n");
		return 1;
	}

	sprintf_append(mem_ctx, &string, &len, &bufsize, "");
	assert(strlen(string) == len);
	sprintf_append(mem_ctx, &string, &len, &bufsize, "");
	assert(strlen(string) == len);
	sprintf_append(mem_ctx, &string, &len, &bufsize,
		       "01234567890123456789012345678901234567890123456789\n");
	assert(strlen(string) == len);


	for (i=0; i<(100000); i++) {
		if (i%1000 == 0) {
			printf("%d %d\r", i, bufsize);
			fflush(stdout);
		}
		sprintf_append(mem_ctx, &string, &len, &bufsize, "%d\n", i);
		assert(strlen(string) == len);
	}

	talloc_destroy(mem_ctx);

	return 0;
}