1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Calls bsearch to find a character in a sorted buffer, and
10** verifies that the correct position is returned.
11**
12**
13**==========================================================================*/
14
15#include <palsuite.h>
16
17int __cdecl charcmp(const void *pa, const void *pb)
18{
19 return memcmp(pa, pb, 1);
20}
21
22int __cdecl main(int argc, char **argv)
23{
24
25 const char array[] = "abcdefghij";
26 char * found=NULL;
27
28 /*
29 * Initialize the PAL and return FAIL if this fails
30 */
31 if (0 != (PAL_Initialize(argc, argv)))
32 {
33 return FAIL;
34 }
35
36 found = (char *)bsearch(&"d", array, sizeof(array) - 1, (sizeof(char))
37 , charcmp);
38 if (found != array + 3)
39 {
40 Fail ("bsearch was unable to find a specified character in a "
41 "sorted list.\n");
42 }
43 PAL_Terminate();
44 return PASS;
45}
46
47
48
49