xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/string/string01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker /* 01/02/2003	Port to LTP [email protected] */
21*49cdfc7eSAndroid Build Coastguard Worker /* 06/30/2001	Port to Linux	[email protected] */
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker /*
24*49cdfc7eSAndroid Build Coastguard Worker  * NAME
25*49cdfc7eSAndroid Build Coastguard Worker  *	string01.c -  check string functions.
26*49cdfc7eSAndroid Build Coastguard Worker  *
27*49cdfc7eSAndroid Build Coastguard Worker  * CALLS
28*49cdfc7eSAndroid Build Coastguard Worker  *	strchr, strrchr, strcat, strcmp, strcpy, strlen,
29*49cdfc7eSAndroid Build Coastguard Worker  *	  strncat, strncmp, strncpy
30*49cdfc7eSAndroid Build Coastguard Worker  *
31*49cdfc7eSAndroid Build Coastguard Worker  * ALGORITHM
32*49cdfc7eSAndroid Build Coastguard Worker  *	Test functionality of the string functions:
33*49cdfc7eSAndroid Build Coastguard Worker  *		(strchr, strrchr, strcat, strcmp, strcpy, strlen,
34*49cdfc7eSAndroid Build Coastguard Worker  *		 strncat, strncmp, strncpy )
35*49cdfc7eSAndroid Build Coastguard Worker  *
36*49cdfc7eSAndroid Build Coastguard Worker  */
37*49cdfc7eSAndroid Build Coastguard Worker 
38*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
39*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
40*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
47*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
48*49cdfc7eSAndroid Build Coastguard Worker 
49*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "string01";
50*49cdfc7eSAndroid Build Coastguard Worker 
51*49cdfc7eSAndroid Build Coastguard Worker int local_flag = PASSED;
52*49cdfc7eSAndroid Build Coastguard Worker int block_number;
53*49cdfc7eSAndroid Build Coastguard Worker FILE *temp;
54*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
55*49cdfc7eSAndroid Build Coastguard Worker /*****	**	** *****/
56*49cdfc7eSAndroid Build Coastguard Worker 
57*49cdfc7eSAndroid Build Coastguard Worker #define LONGSTR	(96*1024-1)
58*49cdfc7eSAndroid Build Coastguard Worker /* #define LONGSTR	(1024-1)		*/
59*49cdfc7eSAndroid Build Coastguard Worker 
60*49cdfc7eSAndroid Build Coastguard Worker /*
61*49cdfc7eSAndroid Build Coastguard Worker  *	Miscellaneous data strings for testing.
62*49cdfc7eSAndroid Build Coastguard Worker  */
63*49cdfc7eSAndroid Build Coastguard Worker 
64*49cdfc7eSAndroid Build Coastguard Worker char tiat[] = "This is a test of the string functions.  ";
65*49cdfc7eSAndroid Build Coastguard Worker char yat[] = "This is yet another test.";
66*49cdfc7eSAndroid Build Coastguard Worker char tiatyat[] =
67*49cdfc7eSAndroid Build Coastguard Worker     "This is a test of the string functions.  This is yet another test.";
68*49cdfc7eSAndroid Build Coastguard Worker 
69*49cdfc7eSAndroid Build Coastguard Worker char longstr[LONGSTR + 1];	/* a very long string */
70*49cdfc7eSAndroid Build Coastguard Worker char dst0[LONGSTR + 1];		/* place holders for various tests */
71*49cdfc7eSAndroid Build Coastguard Worker char dst1[LONGSTR + 1];
72*49cdfc7eSAndroid Build Coastguard Worker char dst2[LONGSTR + 1];
73*49cdfc7eSAndroid Build Coastguard Worker 
74*49cdfc7eSAndroid Build Coastguard Worker 
75*49cdfc7eSAndroid Build Coastguard Worker /*	Strlen	(strlen( s ) == e_res)		*/
76*49cdfc7eSAndroid Build Coastguard Worker struct t_strlen {
77*49cdfc7eSAndroid Build Coastguard Worker 	char *s;
78*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
79*49cdfc7eSAndroid Build Coastguard Worker } t_len[] = {
80*49cdfc7eSAndroid Build Coastguard Worker 	{
81*49cdfc7eSAndroid Build Coastguard Worker 	"", 0}, {
82*49cdfc7eSAndroid Build Coastguard Worker 	"12345", 5}, {
83*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 41}, {
84*49cdfc7eSAndroid Build Coastguard Worker 	longstr, LONGSTR}, {
85*49cdfc7eSAndroid Build Coastguard Worker 	NULL, 0}
86*49cdfc7eSAndroid Build Coastguard Worker };
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker /*	Index	(index( s, c ) == e_res)		*/
89*49cdfc7eSAndroid Build Coastguard Worker struct t_index {
90*49cdfc7eSAndroid Build Coastguard Worker 	char *s;
91*49cdfc7eSAndroid Build Coastguard Worker 	char c;
92*49cdfc7eSAndroid Build Coastguard Worker 	char *e_res;
93*49cdfc7eSAndroid Build Coastguard Worker } t_index[] = {
94*49cdfc7eSAndroid Build Coastguard Worker 	{
95*49cdfc7eSAndroid Build Coastguard Worker 	"", 'z', NULL}, {
96*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'a', tiat + 8}, {
97*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 's', tiat + 3}, {
98*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'o', tiat + 15}, {
99*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'z', NULL}, {
100*49cdfc7eSAndroid Build Coastguard Worker 	NULL, 0, NULL}
101*49cdfc7eSAndroid Build Coastguard Worker };
102*49cdfc7eSAndroid Build Coastguard Worker 
103*49cdfc7eSAndroid Build Coastguard Worker /*	Rindex	(rindex( s, c ) == e_res)		*/
104*49cdfc7eSAndroid Build Coastguard Worker struct t_rindex {
105*49cdfc7eSAndroid Build Coastguard Worker 	char *s;
106*49cdfc7eSAndroid Build Coastguard Worker 	char c;
107*49cdfc7eSAndroid Build Coastguard Worker 	char *e_res;
108*49cdfc7eSAndroid Build Coastguard Worker } t_rindex[] = {
109*49cdfc7eSAndroid Build Coastguard Worker 	{
110*49cdfc7eSAndroid Build Coastguard Worker 	"", 'z', NULL}, {
111*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'a', tiat + 8}, {
112*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 's', tiat + 37}, {
113*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'o', tiat + 35}, {
114*49cdfc7eSAndroid Build Coastguard Worker 	tiat, 'z', NULL}, {
115*49cdfc7eSAndroid Build Coastguard Worker 	NULL, 0, NULL}
116*49cdfc7eSAndroid Build Coastguard Worker };
117*49cdfc7eSAndroid Build Coastguard Worker 
118*49cdfc7eSAndroid Build Coastguard Worker /*	Strcmp	(strcmp( s1, s2 ) == e_res)		*/
119*49cdfc7eSAndroid Build Coastguard Worker struct t_strcmp {
120*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
121*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
122*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
123*49cdfc7eSAndroid Build Coastguard Worker } t_cmp[] = {
124*49cdfc7eSAndroid Build Coastguard Worker 	{
125*49cdfc7eSAndroid Build Coastguard Worker 	"", "", 0}, {
126*49cdfc7eSAndroid Build Coastguard Worker 	"", tiat, -((int)'T')}, {
127*49cdfc7eSAndroid Build Coastguard Worker 	tiat, "", 'T'}, {
128*49cdfc7eSAndroid Build Coastguard Worker 	tiat, tiat, 0}, {
129*49cdfc7eSAndroid Build Coastguard Worker 	yat, tiat, 'y' - 'a'}, {
130*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, 0}
131*49cdfc7eSAndroid Build Coastguard Worker };
132*49cdfc7eSAndroid Build Coastguard Worker 
133*49cdfc7eSAndroid Build Coastguard Worker /*	Strcat	(strcmp( strcat(s1, s2),  s1s2 ) == e_res)		*/
134*49cdfc7eSAndroid Build Coastguard Worker /*	ASSUMES strcmp is working -- it is tested prior to strcat	*/
135*49cdfc7eSAndroid Build Coastguard Worker struct t_strcat {
136*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
137*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
138*49cdfc7eSAndroid Build Coastguard Worker 	char *s1s2;
139*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
140*49cdfc7eSAndroid Build Coastguard Worker } t_cat[] = {
141*49cdfc7eSAndroid Build Coastguard Worker 	{
142*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", "", 0}, {
143*49cdfc7eSAndroid Build Coastguard Worker 	dst0, tiat, tiat, 0}, {
144*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", tiat, 0}, {
145*49cdfc7eSAndroid Build Coastguard Worker 	dst0, yat, tiatyat, 0}, {
146*49cdfc7eSAndroid Build Coastguard Worker 	dst1, longstr, longstr, 0}, {
147*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, NULL, 0}
148*49cdfc7eSAndroid Build Coastguard Worker };
149*49cdfc7eSAndroid Build Coastguard Worker 
150*49cdfc7eSAndroid Build Coastguard Worker /*	Strcpy	(strcmp( strcpy(s1, s2),  s1s2 ) == e_res)		*/
151*49cdfc7eSAndroid Build Coastguard Worker /*	ASSUMES strcmp is working -- it is tested prior to strcpy	*/
152*49cdfc7eSAndroid Build Coastguard Worker /*	No overlapping copies are tested				*/
153*49cdfc7eSAndroid Build Coastguard Worker struct t_strcpy {
154*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
155*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
156*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
157*49cdfc7eSAndroid Build Coastguard Worker } t_cpy[] = {
158*49cdfc7eSAndroid Build Coastguard Worker 	{
159*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", 0}, {
160*49cdfc7eSAndroid Build Coastguard Worker 	dst0, tiat, 0}, {
161*49cdfc7eSAndroid Build Coastguard Worker 	dst0, longstr, 0}, {
162*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, 0}
163*49cdfc7eSAndroid Build Coastguard Worker };
164*49cdfc7eSAndroid Build Coastguard Worker 
165*49cdfc7eSAndroid Build Coastguard Worker /*	Strncmp	(strncmp( s1, s2 ) == e_res)		*/
166*49cdfc7eSAndroid Build Coastguard Worker struct t_strncmp {
167*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
168*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
169*49cdfc7eSAndroid Build Coastguard Worker 	int n;
170*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
171*49cdfc7eSAndroid Build Coastguard Worker 	int a_res;		/* Allowable results, some platforms only return 1 or -1 */
172*49cdfc7eSAndroid Build Coastguard Worker } t_ncmp[] = {
173*49cdfc7eSAndroid Build Coastguard Worker 	{
174*49cdfc7eSAndroid Build Coastguard Worker 	"", "", 0, 0, 0}, {
175*49cdfc7eSAndroid Build Coastguard Worker 	"", "", 80, 0, 0}, {
176*49cdfc7eSAndroid Build Coastguard Worker 	tiat, "", 0, 0, 0}, {
177*49cdfc7eSAndroid Build Coastguard Worker 	"", tiat, 80, -((int)'T'), -1}, {
178*49cdfc7eSAndroid Build Coastguard Worker 	tiat, "", 80, 'T', 1}, {
179*49cdfc7eSAndroid Build Coastguard Worker 	tiat, tiat, 80, 0, 0}, {
180*49cdfc7eSAndroid Build Coastguard Worker 	yat, tiat, 80, 'y' - 'a', 1}, {
181*49cdfc7eSAndroid Build Coastguard Worker 	yat, tiat, 8, 0, 1}, {
182*49cdfc7eSAndroid Build Coastguard Worker 	yat, tiat, 9, 'y' - 'a', 1}, {
183*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, 0, 0, 0}
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker };
186*49cdfc7eSAndroid Build Coastguard Worker 
187*49cdfc7eSAndroid Build Coastguard Worker /*	Strncat	(strcmp( strncat(s1, s2, n),  s1ns2 ) == e_res)	*/
188*49cdfc7eSAndroid Build Coastguard Worker /*	ASSUMES strcmp is working -- it is tested prior to strncat	*/
189*49cdfc7eSAndroid Build Coastguard Worker /*	dest is guaranteed to be all '\0' s at start of test		*/
190*49cdfc7eSAndroid Build Coastguard Worker struct t_strncat {
191*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
192*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
193*49cdfc7eSAndroid Build Coastguard Worker 	int n;
194*49cdfc7eSAndroid Build Coastguard Worker 	char *s1ns2;
195*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
196*49cdfc7eSAndroid Build Coastguard Worker } t_ncat[] = {
197*49cdfc7eSAndroid Build Coastguard Worker 	/*      Regular strcat stuff -- i.e., n is large enough         */
198*49cdfc7eSAndroid Build Coastguard Worker 	{
199*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", LONGSTR, "", 0}, {
200*49cdfc7eSAndroid Build Coastguard Worker 	dst0, tiat, LONGSTR, tiat, 0}, {
201*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", LONGSTR, tiat, 0}, {
202*49cdfc7eSAndroid Build Coastguard Worker 	dst0, yat, LONGSTR, tiatyat, 0}, {
203*49cdfc7eSAndroid Build Coastguard Worker 	dst1, longstr, LONGSTR, longstr, 0},
204*49cdfc7eSAndroid Build Coastguard Worker 	    /*      Restricted strcat stuff                                 */
205*49cdfc7eSAndroid Build Coastguard Worker 	{
206*49cdfc7eSAndroid Build Coastguard Worker 	dst2, longstr, 0, "", 0}, {
207*49cdfc7eSAndroid Build Coastguard Worker 	dst2, longstr, 1, "t", 0}, {
208*49cdfc7eSAndroid Build Coastguard Worker 	dst2, longstr, LONGSTR - 1, longstr, 0}, {
209*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, 0, NULL, 0}
210*49cdfc7eSAndroid Build Coastguard Worker 
211*49cdfc7eSAndroid Build Coastguard Worker };
212*49cdfc7eSAndroid Build Coastguard Worker 
213*49cdfc7eSAndroid Build Coastguard Worker /*	Strncpy	(strcmp( strncpy(s1, s2),  s1n ) == e_res)		*/
214*49cdfc7eSAndroid Build Coastguard Worker /*	ASSUMES strcmp is working -- it is tested prior to strncpy	*/
215*49cdfc7eSAndroid Build Coastguard Worker /*	No overlapping copies are tested				*/
216*49cdfc7eSAndroid Build Coastguard Worker struct t_strncpy {
217*49cdfc7eSAndroid Build Coastguard Worker 	char *s1;
218*49cdfc7eSAndroid Build Coastguard Worker 	char *s2;
219*49cdfc7eSAndroid Build Coastguard Worker 	int n;
220*49cdfc7eSAndroid Build Coastguard Worker 	char *s1n;
221*49cdfc7eSAndroid Build Coastguard Worker 	int e_res;
222*49cdfc7eSAndroid Build Coastguard Worker } t_ncpy[] = {
223*49cdfc7eSAndroid Build Coastguard Worker 	/*      Regular strcpy stuff -- i.e., n is large enough         */
224*49cdfc7eSAndroid Build Coastguard Worker 	{
225*49cdfc7eSAndroid Build Coastguard Worker 	dst0, "", LONGSTR, "", 0}, {
226*49cdfc7eSAndroid Build Coastguard Worker 	dst0, tiat, LONGSTR, tiat, 0}, {
227*49cdfc7eSAndroid Build Coastguard Worker 	dst0, longstr, LONGSTR, longstr, 0},
228*49cdfc7eSAndroid Build Coastguard Worker 	    /*      Restricted strcpy stuff                                 */
229*49cdfc7eSAndroid Build Coastguard Worker 	{
230*49cdfc7eSAndroid Build Coastguard Worker 	dst1, tiat, 0, "", 0}, {
231*49cdfc7eSAndroid Build Coastguard Worker 	dst1, longstr, 5, "ttttt", 0}, {
232*49cdfc7eSAndroid Build Coastguard Worker 	NULL, NULL, 0, NULL, 0}
233*49cdfc7eSAndroid Build Coastguard Worker };
234*49cdfc7eSAndroid Build Coastguard Worker 
235*49cdfc7eSAndroid Build Coastguard Worker void setup();
236*49cdfc7eSAndroid Build Coastguard Worker int blenter();
237*49cdfc7eSAndroid Build Coastguard Worker int blexit();
238*49cdfc7eSAndroid Build Coastguard Worker int anyfail();
239*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)240*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
241*49cdfc7eSAndroid Build Coastguard Worker {
242*49cdfc7eSAndroid Build Coastguard Worker 	temp = stderr;
243*49cdfc7eSAndroid Build Coastguard Worker }
244*49cdfc7eSAndroid Build Coastguard Worker 
blenter(void)245*49cdfc7eSAndroid Build Coastguard Worker int blenter(void)
246*49cdfc7eSAndroid Build Coastguard Worker {
247*49cdfc7eSAndroid Build Coastguard Worker 	local_flag = PASSED;
248*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
249*49cdfc7eSAndroid Build Coastguard Worker }
250*49cdfc7eSAndroid Build Coastguard Worker 
blexit(void)251*49cdfc7eSAndroid Build Coastguard Worker int blexit(void)
252*49cdfc7eSAndroid Build Coastguard Worker {
253*49cdfc7eSAndroid Build Coastguard Worker 	(local_flag == PASSED) ? tst_resm(TPASS,
254*49cdfc7eSAndroid Build Coastguard Worker 					  "Test passed") : tst_resm(TFAIL,
255*49cdfc7eSAndroid Build Coastguard Worker 								    "Test failed");
256*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
257*49cdfc7eSAndroid Build Coastguard Worker }
258*49cdfc7eSAndroid Build Coastguard Worker 
anyfail(void)259*49cdfc7eSAndroid Build Coastguard Worker int anyfail(void)
260*49cdfc7eSAndroid Build Coastguard Worker {
261*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
262*49cdfc7eSAndroid Build Coastguard Worker }
263*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char * argv[])264*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
265*49cdfc7eSAndroid Build Coastguard Worker {
266*49cdfc7eSAndroid Build Coastguard Worker 	register int n, i;
267*49cdfc7eSAndroid Build Coastguard Worker 	char *s, *pr;
268*49cdfc7eSAndroid Build Coastguard Worker 
269*49cdfc7eSAndroid Build Coastguard Worker 	tst_parse_opts(argc, argv, NULL, NULL);
270*49cdfc7eSAndroid Build Coastguard Worker 
271*49cdfc7eSAndroid Build Coastguard Worker 	/*
272*49cdfc7eSAndroid Build Coastguard Worker 	 * Init longstr
273*49cdfc7eSAndroid Build Coastguard Worker 	 */
274*49cdfc7eSAndroid Build Coastguard Worker 
275*49cdfc7eSAndroid Build Coastguard Worker 	s = longstr;
276*49cdfc7eSAndroid Build Coastguard Worker 	n = LONGSTR;
277*49cdfc7eSAndroid Build Coastguard Worker 	while (n--)
278*49cdfc7eSAndroid Build Coastguard Worker 		*s++ = 't';
279*49cdfc7eSAndroid Build Coastguard Worker 	*s = '\0';
280*49cdfc7eSAndroid Build Coastguard Worker 
281*49cdfc7eSAndroid Build Coastguard Worker 	setup();
282*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------*/
283*49cdfc7eSAndroid Build Coastguard Worker 
284*49cdfc7eSAndroid Build Coastguard Worker 	/*
285*49cdfc7eSAndroid Build Coastguard Worker 	 * Index
286*49cdfc7eSAndroid Build Coastguard Worker 	 */
287*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrchr\n" );
288*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
289*49cdfc7eSAndroid Build Coastguard Worker 	while (t_index[i].s) {
290*49cdfc7eSAndroid Build Coastguard Worker 		if ((pr =
291*49cdfc7eSAndroid Build Coastguard Worker 		     strchr(t_index[i].s, t_index[i].c)) != t_index[i].e_res) {
292*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strchr) test %d", i);
293*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
294*49cdfc7eSAndroid Build Coastguard Worker 		}
295*49cdfc7eSAndroid Build Coastguard Worker 		i++;
296*49cdfc7eSAndroid Build Coastguard Worker 	}
297*49cdfc7eSAndroid Build Coastguard Worker 	/*
298*49cdfc7eSAndroid Build Coastguard Worker 	 * Strrchr
299*49cdfc7eSAndroid Build Coastguard Worker 	 */
300*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrrchr\n" );
301*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
302*49cdfc7eSAndroid Build Coastguard Worker 	while (t_rindex[i].s) {
303*49cdfc7eSAndroid Build Coastguard Worker 		if ((pr = strrchr(t_rindex[i].s, t_rindex[i].c))
304*49cdfc7eSAndroid Build Coastguard Worker 		    != t_rindex[i].e_res) {
305*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strrchr) test %d", i);
306*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
307*49cdfc7eSAndroid Build Coastguard Worker 		}
308*49cdfc7eSAndroid Build Coastguard Worker 		i++;
309*49cdfc7eSAndroid Build Coastguard Worker 	}
310*49cdfc7eSAndroid Build Coastguard Worker 	/*
311*49cdfc7eSAndroid Build Coastguard Worker 	 * Strlen
312*49cdfc7eSAndroid Build Coastguard Worker 	 */
313*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrlen\n" );
314*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
315*49cdfc7eSAndroid Build Coastguard Worker 	while (t_len[i].s) {
316*49cdfc7eSAndroid Build Coastguard Worker 		if ((n = strlen(t_len[i].s)) != t_len[i].e_res) {
317*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strlen) test %d: expected %d, got %d",
318*49cdfc7eSAndroid Build Coastguard Worker 				i, t_len[i].e_res, n);
319*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
320*49cdfc7eSAndroid Build Coastguard Worker 		}
321*49cdfc7eSAndroid Build Coastguard Worker 		i++;
322*49cdfc7eSAndroid Build Coastguard Worker 	}
323*49cdfc7eSAndroid Build Coastguard Worker 
324*49cdfc7eSAndroid Build Coastguard Worker 	/*
325*49cdfc7eSAndroid Build Coastguard Worker 	 * Strcmp
326*49cdfc7eSAndroid Build Coastguard Worker 	 */
327*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrcmp\n" );
328*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
329*49cdfc7eSAndroid Build Coastguard Worker #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
330*49cdfc7eSAndroid Build Coastguard Worker 	while (t_cmp[i].s1) {
331*49cdfc7eSAndroid Build Coastguard Worker 		n = strcmp(t_cmp[i].s1, t_cmp[i].s2);
332*49cdfc7eSAndroid Build Coastguard Worker 		if (sign(n) != sign(t_cmp[i].e_res)) {
333*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strcmp) test %d: expected %d, got %d",
334*49cdfc7eSAndroid Build Coastguard Worker 				i, sign(t_cmp[i].e_res), sign(n));
335*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
336*49cdfc7eSAndroid Build Coastguard Worker 		}
337*49cdfc7eSAndroid Build Coastguard Worker 		i++;
338*49cdfc7eSAndroid Build Coastguard Worker 	}
339*49cdfc7eSAndroid Build Coastguard Worker 
340*49cdfc7eSAndroid Build Coastguard Worker 	/*
341*49cdfc7eSAndroid Build Coastguard Worker 	 * Strcat
342*49cdfc7eSAndroid Build Coastguard Worker 	 */
343*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrcat\n" );
344*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst0, 0, LONGSTR + 1);	/* clean slate */
345*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst1, 0, LONGSTR + 1);	/* clean slate */
346*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
347*49cdfc7eSAndroid Build Coastguard Worker 	while (t_cat[i].s1) {
348*49cdfc7eSAndroid Build Coastguard Worker 		if ((n =
349*49cdfc7eSAndroid Build Coastguard Worker 		     strcmp(strcat(t_cat[i].s1, t_cat[i].s2), t_cat[i].s1s2))
350*49cdfc7eSAndroid Build Coastguard Worker 		    != t_cat[i].e_res) {
351*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strcat) test %d: expected %d, got %d",
352*49cdfc7eSAndroid Build Coastguard Worker 				i, t_cat[i].e_res, n);
353*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
354*49cdfc7eSAndroid Build Coastguard Worker 		}
355*49cdfc7eSAndroid Build Coastguard Worker 		i++;
356*49cdfc7eSAndroid Build Coastguard Worker 	}
357*49cdfc7eSAndroid Build Coastguard Worker 
358*49cdfc7eSAndroid Build Coastguard Worker 	/*
359*49cdfc7eSAndroid Build Coastguard Worker 	 * Strcpy
360*49cdfc7eSAndroid Build Coastguard Worker 	 */
361*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrcpy\n" );
362*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
363*49cdfc7eSAndroid Build Coastguard Worker 	while (t_cpy[i].s1) {
364*49cdfc7eSAndroid Build Coastguard Worker 		if ((n = strcmp(strcpy(t_cpy[i].s1, t_cpy[i].s2), t_cpy[i].s2))
365*49cdfc7eSAndroid Build Coastguard Worker 		    != t_cpy[i].e_res) {
366*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strcpy) test %d: expected %d, got %d",
367*49cdfc7eSAndroid Build Coastguard Worker 				i, t_cpy[i].e_res, n);
368*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
369*49cdfc7eSAndroid Build Coastguard Worker 		}
370*49cdfc7eSAndroid Build Coastguard Worker 		i++;
371*49cdfc7eSAndroid Build Coastguard Worker 	}
372*49cdfc7eSAndroid Build Coastguard Worker 
373*49cdfc7eSAndroid Build Coastguard Worker 	/*
374*49cdfc7eSAndroid Build Coastguard Worker 	 * Strncat
375*49cdfc7eSAndroid Build Coastguard Worker 	 */
376*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrncat\n" );
377*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst0, 0, LONGSTR + 1);	/* clean slate */
378*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst1, 0, LONGSTR + 1);	/* clean slate */
379*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst2, 0, LONGSTR + 1);	/* clean slate */
380*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
381*49cdfc7eSAndroid Build Coastguard Worker 	while (t_ncat[i].s1) {
382*49cdfc7eSAndroid Build Coastguard Worker 		if ((n =
383*49cdfc7eSAndroid Build Coastguard Worker 		     strcmp(strncat(t_ncat[i].s1, t_ncat[i].s2, t_ncat[i].n),
384*49cdfc7eSAndroid Build Coastguard Worker 			    t_ncat[i].s1ns2)) != t_ncat[i].e_res) {
385*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strncat) test %d: expected %d, got %d",
386*49cdfc7eSAndroid Build Coastguard Worker 				i, t_ncat[i].e_res, n);
387*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
388*49cdfc7eSAndroid Build Coastguard Worker 		}
389*49cdfc7eSAndroid Build Coastguard Worker 		i++;
390*49cdfc7eSAndroid Build Coastguard Worker 	}
391*49cdfc7eSAndroid Build Coastguard Worker 
392*49cdfc7eSAndroid Build Coastguard Worker 	/*
393*49cdfc7eSAndroid Build Coastguard Worker 	 * Strncmp
394*49cdfc7eSAndroid Build Coastguard Worker 	 */
395*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrncmp\n" );
396*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
397*49cdfc7eSAndroid Build Coastguard Worker 	while (t_ncmp[i].s1) {
398*49cdfc7eSAndroid Build Coastguard Worker 		if ((n = strncmp(t_ncmp[i].s1, t_ncmp[i].s2, t_ncmp[i].n))
399*49cdfc7eSAndroid Build Coastguard Worker 		    != t_ncmp[i].e_res) {
400*49cdfc7eSAndroid Build Coastguard Worker 			if ((t_ncmp[i].a_res < 0 && n > t_ncmp[i].a_res)
401*49cdfc7eSAndroid Build Coastguard Worker 			    || (t_ncmp[i].a_res > 0 && n < t_ncmp[i].a_res)) {
402*49cdfc7eSAndroid Build Coastguard Worker 				fprintf(temp,
403*49cdfc7eSAndroid Build Coastguard Worker 					"(Strncmp) test %d: expected %d, got %d",
404*49cdfc7eSAndroid Build Coastguard Worker 					i, t_ncmp[i].e_res, n);
405*49cdfc7eSAndroid Build Coastguard Worker 				local_flag = FAILED;
406*49cdfc7eSAndroid Build Coastguard Worker 			}
407*49cdfc7eSAndroid Build Coastguard Worker 		}
408*49cdfc7eSAndroid Build Coastguard Worker 		i++;
409*49cdfc7eSAndroid Build Coastguard Worker 	}
410*49cdfc7eSAndroid Build Coastguard Worker 
411*49cdfc7eSAndroid Build Coastguard Worker 	/*
412*49cdfc7eSAndroid Build Coastguard Worker 	 * Strncpy
413*49cdfc7eSAndroid Build Coastguard Worker 	 */
414*49cdfc7eSAndroid Build Coastguard Worker 	//fprintf(temp, "\tStrncpy\n" );
415*49cdfc7eSAndroid Build Coastguard Worker 	i = 0;
416*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst0, 0, LONGSTR + 1);	/* clean slate */
417*49cdfc7eSAndroid Build Coastguard Worker 	memset(dst1, 0, LONGSTR + 1);	/* clean slate */
418*49cdfc7eSAndroid Build Coastguard Worker 	while (t_ncpy[i].s1) {
419*49cdfc7eSAndroid Build Coastguard Worker 		if ((n =
420*49cdfc7eSAndroid Build Coastguard Worker 		     strcmp(strncpy(t_ncpy[i].s1, t_ncpy[i].s2, t_ncpy[i].n),
421*49cdfc7eSAndroid Build Coastguard Worker 			    t_ncpy[i].s1n)) != t_ncpy[i].e_res) {
422*49cdfc7eSAndroid Build Coastguard Worker 			fprintf(temp, "(Strncpy) test %d: expected %d, got %d",
423*49cdfc7eSAndroid Build Coastguard Worker 				i, t_ncpy[i].e_res, n);
424*49cdfc7eSAndroid Build Coastguard Worker 			local_flag = FAILED;
425*49cdfc7eSAndroid Build Coastguard Worker 		}
426*49cdfc7eSAndroid Build Coastguard Worker 		i++;
427*49cdfc7eSAndroid Build Coastguard Worker 	}
428*49cdfc7eSAndroid Build Coastguard Worker 
429*49cdfc7eSAndroid Build Coastguard Worker 	blexit();
430*49cdfc7eSAndroid Build Coastguard Worker 	anyfail();
431*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
432*49cdfc7eSAndroid Build Coastguard Worker }
433