Module: sip-router
Branch: master
Commit: c8421620772184d28fd5b08d09b1e64cf0a8866a
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c8421620772184d28fd5b08d09b1e64cf0a8866a

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Sun Aug 19 12:52:51 2012 +0200

core: added q_memrchr(...)

- reverse search for char in a buffer

---

 ut.h |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ut.h b/ut.h
index 5e9e277..8f04736 100644
--- a/ut.h
+++ b/ut.h
@@ -432,7 +432,7 @@ static inline char* ushort2str(unsigned short u)
 
 
 
-/* faster memchr version */
+/* fast memchr version */
 static inline char* q_memchr(char* p, int c, unsigned int size)
 {
        char* end;
@@ -443,7 +443,20 @@ static inline char* q_memchr(char* p, int c, unsigned int 
size)
        }
        return 0;
 }
-       
+
+
+/* fast reverse char search */
+
+static inline char* q_memrchr(char* p, int c, unsigned int size)
+{
+       char* end;
+
+       end=p+size-1;
+       for(;end>=p;end--) {
+               if (*end==(unsigned char)c) return end;
+       }
+       return 0;
+}
 
 /* returns -1 on error, 1! on success (consistent with int2reverse_hex) */
 inline static int reverse_hex2int( char *c, int len, unsigned int* res)


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to