Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/strlcpycat.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2938 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 #include <stdio.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 int main(void)
7 {
8 char temp[8];
9 size_t len;
10
11 printf("strlcpy:\n");
12 len = strlcpy(temp, "123", sizeof(temp));
13 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
14 if (strcmp(temp, "123") != 0)
15 goto error;
16
17 len = strlcpy(temp, "", sizeof(temp));
18 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
19 if (strcmp(temp, "") != 0)
20 goto error;
21
22 len = strlcpy(temp, "1234567890", sizeof(temp));
23 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
24 if (strcmp(temp, "1234567") != 0)
25 goto error;
26
27 len = strlcpy(temp, "123", 1);
28 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
29 if (strcmp(temp, "") != 0)
30 goto error;
31
32 len = strlcpy(temp, "1234567890", 1);
33 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
34 if (strcmp(temp, "") != 0)
35 goto error;
36
37 len = strlcpy(temp, "123", 0);
38 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
39 if (strcmp(temp, "") != 0)
40 goto error;
41
42 len = strlcpy(temp, "1234567890", 0);
43 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
44 if (strcmp(temp, "") != 0)
45 goto error;
46
47 len = strlcpy(temp, "1234567", sizeof(temp));
48 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
49 if (strcmp(temp, "1234567") != 0)
50 goto error;
51
52 len = strlcpy(temp, "12345678", sizeof(temp));
53 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
54 if (strcmp(temp, "1234567") != 0)
55 goto error;
56
57 printf("\n");
58 printf("strlcat:\n");
59 strcpy(temp, "");
60 len = strlcat(temp, "123", sizeof(temp));
61 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
62 if (strcmp(temp, "123") != 0)
63 goto error;
64
65 strcpy(temp, "ABC");
66 len = strlcat(temp, "", sizeof(temp));
67 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
68 if (strcmp(temp, "ABC") != 0)
69 goto error;
70
71 strcpy(temp, "");
72 len = strlcat(temp, "", sizeof(temp));
73 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
74 if (strcmp(temp, "") != 0)
75 goto error;
76
77 strcpy(temp, "ABC");
78 len = strlcat(temp, "123", sizeof(temp));
79 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
80 if (strcmp(temp, "ABC123") != 0)
81 goto error;
82
83 strcpy(temp, "ABC");
84 len = strlcat(temp, "1234567890", sizeof(temp));
85 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
86 if (strcmp(temp, "ABC1234") != 0)
87 goto error;
88
89 strcpy(temp, "ABC");
90 len = strlcat(temp, "123", 5);
91 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
92 if (strcmp(temp, "ABC1") != 0)
93 goto error;
94
95 strcpy(temp, "ABC");
96 len = strlcat(temp, "123", 1);
97 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
98 if (strcmp(temp, "ABC") != 0)
99 goto error;
100
101 strcpy(temp, "ABC");
102 len = strlcat(temp, "123", 0);
103 printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));
104 if (strcmp(temp, "ABC") != 0)
105 goto error;
106
107 exit(0);
108 error:
109 printf("unexpected result\n");
110 exit(1);
111 }