home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / MEMCHR.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.6 KB  |  69 lines

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