[go: up one dir, main page]

File: s-exp-str.c

package info (click to toggle)
uftrace 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,356 kB
  • sloc: ansic: 49,770; python: 11,181; asm: 837; makefile: 769; sh: 637; cpp: 627; javascript: 191
file content (43 lines) | stat: -rw-r--r-- 561 bytes parent folder | download | duplicates (5)
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
char *str_cat(char *d, char *s)
{
	char *p = d;

	while (*d)
		d++;

	while (*d++ = *s++)
		continue;

	return p;
}

char *str_cpy(char *d, char *s)
{
	char *p = d;

	while (*d++ = *s++)
		continue;

	return p;
}

char a[32];
char b[32];

int main(void)
{
	char *c;

	/*
	 * string arguments are aligned in 8-byte boundary including
	 * 2-byte length prefix so checking strings with length of
	 * 5, 6 and 7 will be enough.
	 */
	str_cpy(a, "hello");
	str_cpy(b, " world");
	c = str_cat(a, b);
	str_cpy(a, "goodbye");
	c = str_cat(a, b);

	return *c ? 0 : 1;
}