comparison packages/redboot/current/src/misc_funs.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children eb9fd8c04db3
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //==========================================================================
2 //
3 // misc_funs.c
4 //
5 // Miscellaneous [library] functions for RedBoot
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //==========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): gthomas
35 // Contributors: gthomas
36 // Date: 2000-07-14
37 // Purpose:
38 // Description:
39 //
40 // This code is part of RedBoot (tm).
41 //
42 //####DESCRIPTIONEND####
43 //
44 //==========================================================================
45
46 #include <redboot.h>
47
48 int
49 strlen(const char *s)
50 {
51 int len = 0;
52 while (*s++) len++;
53 return len;
54 }
55
56 int
57 strcmp(const char *s1, const char *s2)
58 {
59 char c1, c2;
60
61 while ((c1 = *s1++) == (c2 = *s2++))
62 if (c1 == 0)
63 return (0);
64 return ((unsigned char)c1 - (unsigned char)c2);
65 }
66
67 void
68 strcpy(char *s1, const char *s2)
69 {
70 char c;
71
72 while ((c = *s2++) != '\0')
73 *s1++ = c;
74 *s1 = '\0';
75 }
76
77 int
78 strcmpci(const char *s1, const char *s2)
79 {
80 char c1, c2;
81 while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
82 if (c1 == 0)
83 return (0);
84 return ((unsigned char)c1 - (unsigned char)c2);
85 }
86
87 int
88 strncmp(const char *s1, const char *s2, int len)
89 {
90 char c1, c2;
91
92 if (len == 0)
93 return 0;
94 do {
95 if ((c1 = *s1++) != (c2 = *s2++))
96 return ((unsigned char)c1 - (unsigned char)c2);
97 if (c1 == 0)
98 break;
99 } while (--len != 0);
100 return 0;
101 }
102
103 int
104 strncmpci(const char *s1, const char *s2, int len)
105 {
106 char c1, c2;
107
108 if (len == 0)
109 return 0;
110 do {
111 if ((c1 = tolower(*s1++)) != (c2 = tolower(*s2++)))
112 return ((unsigned char)c1 - (unsigned char)c2);
113 if (c1 == 0)
114 break;
115 } while (--len != 0);
116 return 0;
117 }
118
119 void
120 memmove(unsigned char *dst, unsigned char *src, int len)
121 {
122 while (len-- > 0) *dst++ = *src++;
123 }
124
125 int
126 memcmp(const unsigned char *dst, const unsigned char *src, int len)
127 {
128 while (len-- > 0) {
129 if (*dst++ != *src++) {
130 return (*--dst - *--src);
131 }
132 }
133 return 0;
134 }
135
136 void
137 memset(unsigned char *dst, unsigned char val, int len)
138 {
139 while (--len >= 0) {
140 *dst++ = val;
141 }
142 }