home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / MEMCHR.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  1.9 KB  |  65 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - memchr.cas
  3.  *
  4.  * function(s)
  5.  *        memchr - search for a character
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <mem.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name        memchr - search for a character
  25.  
  26. Usage        void *memchr(const void *s, int val, size_t n);
  27.  
  28. Prototype in    mem.h & string.h
  29.  
  30. Description    memchr scans up to n bytes at the memory location s looking
  31.         for a match to val.
  32.  
  33. Return value    If  val  was matched then the  return value is a  pointer to
  34.         the first matching position, otherwise it is NULL.
  35.  
  36. *------------------------------------------------------------------------*/
  37. #undef memchr                  /* not an intrinsic */
  38. void *memchr(const void *s, int val, size_t n)
  39. {
  40. #if !(LDATA)
  41.         _ES = _DS;
  42. #endif
  43. asm     LES_    di, s
  44. asm     mov     cx, n
  45. asm     jcxz    mch_NULL
  46. asm     mov     al, val
  47. asm     cld
  48. asm     repne   scasb
  49. asm     je      mch_OK
  50. mch_NULL:
  51. #if (LDATA)
  52. asm     xor     di, di
  53. asm     mov     es, di
  54. #endif
  55. asm     mov     di, 1
  56.  
  57. mch_OK:
  58. asm     dec     di
  59. #if (LDATA)
  60.         return (void _es *) _DI;
  61. #else
  62.         return (void *) _DI;
  63. #endif
  64. }
  65.