1 /* Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <tst-stack-align.h>
42 #define narr (sizeof (arr) / sizeof (arr[0]))
44 static int align_check
;
47 comp (const void *p1
, const void *p2
)
49 struct entry
*e1
= (struct entry
*) p1
;
50 struct entry
*e2
= (struct entry
*) p2
;
53 align_check
= TEST_STACK_ALIGN () ? -1 : 1;
55 return e1
->val
- e2
->val
;
67 for (cnt
= 0; cnt
< narr
; ++cnt
)
70 key
.val
= arr
[cnt
].val
;
72 res
= (struct entry
*) bsearch (&key
, arr
, narr
, sizeof (arr
[0]), comp
);
75 printf ("entry %zd not found\n", cnt
);
78 else if (res
!= &arr
[cnt
])
80 puts ("wrong entry returned");
85 /* And some special tests that shouldn't find any entry. */
87 res
= (struct entry
*) bsearch (&key
, arr
, narr
, sizeof (arr
[0]), comp
);
90 puts ("found an entry that's not there");
95 res
= (struct entry
*) bsearch (&key
, arr
, narr
, sizeof (arr
[0]), comp
);
98 puts ("found an entry that's not there");
103 res
= (struct entry
*) bsearch (&key
, arr
, 0, sizeof (arr
[0]), comp
);
106 puts ("found an entry that's not there");
110 /* Now the array contains only one element - no entry should be found. */
111 for (cnt
= 0; cnt
< narr
; ++cnt
)
113 key
.val
= arr
[cnt
].val
;
115 res
= (struct entry
*) bsearch (&key
, &arr
[5], 1, sizeof (arr
[0]), comp
);
120 printf ("entry %zd not found\n", cnt
);
123 else if (res
!= &arr
[cnt
])
125 puts ("wrong entry returned");
129 else if (res
!= NULL
)
131 puts ("found an entry that's not there");
136 if (align_check
== 0)
138 puts ("alignment not checked");
141 else if (align_check
== -1)
143 puts ("stack not sufficiently aligned");