equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifdef __cplusplus |
|
19 extern "C" { |
|
20 #endif |
|
21 |
|
22 char * strchr (const char *p, int ch) |
|
23 { |
|
24 char c; |
|
25 |
|
26 c = ch; |
|
27 for (;; ++p) |
|
28 { |
|
29 if (*p == c) |
|
30 return ((char *)p); |
|
31 if (*p == '\0') |
|
32 return (char *)(0); |
|
33 } |
|
34 /* NOTREACHED */ |
|
35 } |
|
36 |
|
37 unsigned int strlen(const char *str) |
|
38 { |
|
39 const char *s; |
|
40 for (s = str; *s; ++s) { } |
|
41 |
|
42 return(s - str); |
|
43 } |
|
44 |
|
45 int strcmp(const char *s1, const char *s2) |
|
46 { |
|
47 while (*s1 == *s2++) |
|
48 if (*s1++ == 0) |
|
49 return (0); |
|
50 return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); |
|
51 } |
|
52 |
|
53 void * memchr(const void *s, int c, unsigned n) |
|
54 { |
|
55 if (n != 0) |
|
56 { |
|
57 const unsigned char *p = s; |
|
58 do |
|
59 { |
|
60 if (*p++ == (unsigned char)c) |
|
61 return ((void *)(p - 1)); |
|
62 } while (--n != 0); |
|
63 |
|
64 } |
|
65 // Not found |
|
66 return (void *)0; |
|
67 } |
|
68 |
|
69 int memcmp(const void *s1, const void *s2, unsigned n) |
|
70 { |
|
71 if (n != 0) |
|
72 { |
|
73 const unsigned char *p1 = s1, *p2 = s2; |
|
74 |
|
75 do |
|
76 { |
|
77 if (*p1++ != *p2++) |
|
78 return (*--p1 - *--p2); |
|
79 } while (--n != 0); |
|
80 } |
|
81 return (0); |
|
82 } |
|
83 |
|
84 #ifdef __cplusplus |
|
85 } |
|
86 #endif |