Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

4 years ago
  1. /***
  2. *lfind.c - do a linear search
  3. *
  4. * Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _lfind() - do a linear search of an array.
  8. *
  9. *Revision History:
  10. * 06-19-85 TC initial version
  11. * 02-05-87 BM changed <= to < in while condition to fix bug
  12. * of looking one element too far
  13. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  14. * 01-21-88 JCR Backed out _LOAD_DS...
  15. * 10-30-89 JCR Added _cdecl to prototypes
  16. * 03-14-90 GJF Replaced _cdecl with _CALLTYPE1, added #include
  17. * <cruntime.h>, removed #include <register.h> and
  18. * fixed the copyright. Also, cleaned up the formatting
  19. * a bit.
  20. * 04-05-90 GJF Added #include <search.h> and fixed the resulting
  21. * compilation errors and warnings. Also, removed an
  22. * unreferenced local variable.
  23. * 07-25-90 SBM Replaced <stdio.h> by <stddef.h>
  24. * 10-04-90 GJF New-style function declarator.
  25. * 01-17-91 GJF ANSI naming.
  26. *
  27. *******************************************************************************/
  28. #include <cruntime.h>
  29. #include <search.h>
  30. #include <stddef.h>
  31. /***
  32. *char *_lfind(key, base, num, width, compare) - do a linear search
  33. *
  34. *Purpose:
  35. * Performs a linear search on the array, looking for the value key
  36. * in an array of num elements of width bytes in size. Returns
  37. * a pointer to the array value if found, NULL if not found.
  38. *
  39. *Entry:
  40. * char *key - key to search for
  41. * char *base - base of array to search
  42. * unsigned *num - number of elements in array
  43. * int width - number of bytes in each array element
  44. * int (*compare)() - pointer to function that compares two
  45. * array values, returning 0 if they are equal and non-0
  46. * if they are different. Two pointers to array elements
  47. * are passed to this function.
  48. *
  49. *Exit:
  50. * if key found:
  51. * returns pointer to array element
  52. * if key not found:
  53. * returns NULL
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. void * _CALLTYPE1 _lfind (
  59. REG2 const void *key,
  60. REG1 const void *base,
  61. REG3 unsigned int *num,
  62. unsigned int width,
  63. int (_CALLTYPE1 *compare)(const void *, const void *)
  64. )
  65. {
  66. unsigned int place = 0;
  67. while (place < *num )
  68. if (!(*compare)(key,base))
  69. return( (void *)base );
  70. else
  71. {
  72. base = (char *)base + width;
  73. place++;
  74. }
  75. return( NULL );
  76. }