File: memrchr.c

package info (click to toggle)
hercules 3.12-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 13,908 kB
  • ctags: 19,075
  • sloc: ansic: 174,392; sh: 8,780; makefile: 806; perl: 149
file content (39 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* MEMRCHR.C    (c) Copyright Volker Bandke, 2003                    */
/*              Hercules Right to Left memory scan                   */

/*-------------------------------------------------------------------*/
/*      Scans the memory block and reports the last occurrence of    */
/*      the specified byte in the buffer.  Returns a pointer to      */
/*      the byte if found, or NULL if not found.                     */
/*-------------------------------------------------------------------*/

#include "hstdinc.h"

#define _MEMRCHR_C_
#define _HUTIL_DLL_

#include "hercules.h"

#if !defined( HAVE_MEMRCHR )

#include "memrchr.h"

DLL_EXPORT void *memrchr(const void *buf, int c, size_t num)
{
   unsigned char *pMem;
   if (num == 0)
   {
      return NULL;
   }
   for (pMem = (unsigned char *) buf + num - 1; pMem >= (unsigned char *) buf; pMem--)
   {
      if (*pMem == (unsigned char) c) break;
   }
   if (pMem >= (unsigned char *) buf)
   {
      return ((void *) pMem);
   }
   return NULL;
}

#endif // !defined(HAVE_MEMRCHR)