summaryrefslogtreecommitdiff
path: root/firmware/common/memchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/memchr.c')
-rw-r--r--firmware/common/memchr.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/firmware/common/memchr.c b/firmware/common/memchr.c
index a7ff222a61..26bdb9eea3 100644
--- a/firmware/common/memchr.c
+++ b/firmware/common/memchr.c
@@ -1,28 +1,28 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<memchr>>---search for character in memory 3 <<memchr>>---search for character in memory
4 4
5INDEX 5INDEX
6 memchr 6 memchr
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>); 10 void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 void * memchr(<[s1]>, <[c]>, <[n]>); 14 void * memchr(<[s1]>, <[c]>, <[n]>);
15 void *<[string]>; 15 void *<[string]>;
16 int *<[c]>; 16 int *<[c]>;
17 size_t *<[n]>; 17 size_t *<[n]>;
18 18
19DESCRIPTION 19DESCRIPTION
20 This function scans the first <[n]> bytes of the memory pointed 20 This function scans the first <[n]> bytes of the memory pointed
21 to by <[s1]> for the character <[c]> (converted to a char). 21 to by <[s1]> for the character <[c]> (converted to a char).
22 22
23RETURNS 23RETURNS
24 Returns a pointer to the matching byte, or a null pointer if 24 Returns a pointer to the matching byte, or a null pointer if
25 <[c]> does not occur in <[s1]>. 25 <[c]> does not occur in <[s1]>.
26 26
27PORTABILITY 27PORTABILITY
28<<memchr>> is ANSI C. 28<<memchr>> is ANSI C.
@@ -30,7 +30,7 @@ PORTABILITY
30<<memchr>> requires no supporting OS subroutines. 30<<memchr>> requires no supporting OS subroutines.
31 31
32QUICKREF 32QUICKREF
33 memchr ansi pure 33 memchr ansi pure
34*/ 34*/
35 35
36#include <string.h> 36#include <string.h>
@@ -59,8 +59,8 @@ QUICKREF
59 59
60void * 60void *
61_DEFUN (memchr, (s1, i, n), 61_DEFUN (memchr, (s1, i, n),
62 _CONST void *s1 _AND 62 _CONST void *s1 _AND
63 int i _AND size_t n) 63 int i _AND size_t n)
64{ 64{
65 _CONST unsigned char *s = (_CONST unsigned char *)s1; 65 _CONST unsigned char *s = (_CONST unsigned char *)s1;
66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
@@ -69,9 +69,9 @@ _DEFUN (memchr, (s1, i, n),
69 while (n-- > 0) 69 while (n-- > 0)
70 { 70 {
71 if (*s == c) 71 if (*s == c)
72 { 72 {
73 return (void *)s; 73 return (void *)s;
74 } 74 }
75 s++; 75 s++;
76 } 76 }
77 77
@@ -89,15 +89,15 @@ _DEFUN (memchr, (s1, i, n),
89 89
90 aligned_addr = (unsigned long*)s; 90 aligned_addr = (unsigned long*)s;
91 while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE)) 91 while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE))
92 { 92 {
93 aligned_addr++; 93 aligned_addr++;
94 n -= LBLOCKSIZE; 94 n -= LBLOCKSIZE;
95 } 95 }
96 96
97 /* The block of bytes currently pointed to by aligned_addr 97 /* The block of bytes currently pointed to by aligned_addr
98 may contain the target character or there may be less than 98 may contain the target character or there may be less than
99 LBLOCKSIZE bytes left to search. We check the last few 99 LBLOCKSIZE bytes left to search. We check the last few
100 bytes using the bytewise search. */ 100 bytes using the bytewise search. */
101 101
102 s = (unsigned char*)aligned_addr; 102 s = (unsigned char*)aligned_addr;
103 } 103 }
@@ -105,9 +105,9 @@ _DEFUN (memchr, (s1, i, n),
105 while (n-- > 0) 105 while (n-- > 0)
106 { 106 {
107 if (*s == c) 107 if (*s == c)
108 { 108 {
109 return (void *)s; 109 return (void *)s;
110 } 110 }
111 s++; 111 s++;
112 } 112 }
113 113