aboutsummaryrefslogtreecommitdiff
path: root/src/GeneralizedPolynomial-Uniform/test_strlcpy.c
blob: 247c972afbeab93d1c47755c6cbe3574ed661a67 (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
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
/* test_strlcpy -- test driver for Util_Strlcpy() */
/* $Header$ */

#include <string.h>
#include <stdio.h>

#ifndef LOCALINTERP_STANDALONE_BUILD
  #include "cctk.h"
#endif

#include "InterpLocalUniform.h"

/******************************************************************************/

/* prototypes */
size_t tryit(size_t dst_size, const char* src);
void nprint(int n_print, const char* buf);

/* global data structures */
static char buffer[100];

/******************************************************************************/

/*
 * This program is a test driver for  Util_Strlcpy() .
 */

int main(void)
{
size_t n;

n = tryit(9, "hello");
printf("bufsize=9: result=%d buffer=", (int) n);
nprint(9, buffer);

n = tryit(6, "hello");
printf("bufsize=6: result=%d buffer=", (int) n);
nprint(6, buffer);

n = tryit(5, "hello");
printf("bufsize=5: result=%d buffer=", (int) n);
nprint(5, buffer);

n = tryit(4, "hello");
printf("bufsize=4: result=%d buffer=", (int) n);
nprint(4, buffer);

return 0;
}

/******************************************************************************/

size_t tryit(size_t dst_size, const char* src)
{
strcpy(buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
return LocalInterp_Strlcpy(buffer, src, dst_size);
}

/******************************************************************************/

/* print n_print characters of buf[], with visible indication of '\0' */
void nprint(int n_print, const char* buf)
{
int i;

printf("\"");
	for (i = 0 ; i < n_print ; ++i)
	{
	if (buf[i] == '\0')
	   then printf("\\0");
	   else printf("%c", buf[i]);
	}
printf("\"\n");
}