OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [string/] [v2_0/] [src/] [bsdstring.cxx] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//===========================================================================
2
//
3
//      bsdstring.cxx
4
//
5
//      BSD string routines
6
//
7
//===========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//===========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     jlarmour
44
// Contributors:  
45
// Date:          2001-11-27
46
// Purpose:       Provide string functions derived from BSD
47
// Description: 
48
// Usage:         #include <string.h>
49
//
50
//####DESCRIPTIONEND####
51
//
52
//===========================================================================
53
 
54
// CONFIGURATION
55
 
56
#include <pkgconf/libc_string.h>   // Configuration header
57
 
58
// INCLUDES
59
 
60
#include <cyg/infra/cyg_type.h>    // Common type definitions
61
#include <cyg/infra/cyg_trac.h>    // Tracing support
62
#include <cyg/infra/cyg_ass.h>     // Assertion support
63
#include <string.h>                // Header for this file
64
#include <stddef.h>                // size_t, NULL etc.
65
#include <ctype.h>                 // toupper/tolower
66
 
67
// FUNCTIONS
68
 
69
/*---------------------------------------------------------------------*/
70
/* strcasecmp */
71
 
72
__externC int
73
__strcasecmp( const char *s1, const char *s2 )
74
{
75
    CYG_REPORT_FUNCNAMETYPE( "strcasecmp", "returning %d" );
76
    CYG_REPORT_FUNCARG2( "s1=%08x, s2=%08x", s1, s2 );
77
 
78
    CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" );
79
    CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" );
80
 
81
    while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
82
    {
83
        s1++;
84
        s2++;
85
    }
86
 
87
    int ret = tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
88
    CYG_REPORT_RETVAL( ret );
89
    return ret;
90
}
91
 
92
__externC int
93
strcasecmp( const char *s1, const char *s2 ) \
94
  CYGBLD_ATTRIB_WEAK_ALIAS(__strcasecmp);
95
 
96
 
97
/*---------------------------------------------------------------------*/
98
/* strncasecmp */
99
 
100
__externC int
101
__strncasecmp( const char *s1, const char *s2, size_t n )
102
{
103
    CYG_REPORT_FUNCNAMETYPE( "strncasecmp", "returning %d" );
104
    CYG_REPORT_FUNCARG3( "s1=%08x, s2=%08x, n=%d", s1, s2, n );
105
 
106
    if (n == 0)
107
    {
108
        CYG_REPORT_RETVAL(0);
109
        return 0;
110
    }
111
 
112
    CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" );
113
    CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" );
114
 
115
    while (n-- != 0 && tolower(*s1) == tolower(*s2))
116
    {
117
        if (n == 0 || *s1 == '\0' || *s2 == '\0')
118
            break;
119
        s1++;
120
        s2++;
121
    }
122
 
123
    int ret = tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
124
    CYG_REPORT_RETVAL( ret );
125
    return ret;
126
}
127
 
128
__externC int
129
strncasecmp( const char *s1, const char *s2, size_t n ) \
130
  CYGBLD_ATTRIB_WEAK_ALIAS(__strncasecmp);
131
 
132
/*---------------------------------------------------------------------*/
133
/* bcmp */
134
 
135
__externC int
136
__bcmp( const void *s1, const void *s2, size_t n )
137
{
138
    // Don't bother tracing - memcmp can do that
139
    return memcmp (s1, s2, n);
140
}
141
 
142
__externC int
143
bcmp( const void *s1, const void *s2, size_t n ) \
144
  CYGBLD_ATTRIB_WEAK_ALIAS(__bcmp);
145
 
146
/*---------------------------------------------------------------------*/
147
/* bcopy */
148
 
149
__externC void
150
__bcopy( const void *src, void *dest, size_t n )
151
{
152
    // Don't bother tracing - memmove can do that
153
    memmove (dest, src, n);
154
}
155
 
156
__externC void
157
bcopy( const void *src, void *dest, size_t n ) \
158
  CYGBLD_ATTRIB_WEAK_ALIAS(__bcopy);
159
 
160
/*---------------------------------------------------------------------*/
161
/* bzero */
162
 
163
__externC void
164
__bzero( void *s, size_t n )
165
{
166
    // Don't bother tracing - memset can do that
167
    memset( s, 0, n );
168
}
169
 
170
__externC void
171
bzero( void *s, size_t n ) CYGBLD_ATTRIB_WEAK_ALIAS(__bzero);
172
 
173
/*---------------------------------------------------------------------*/
174
/* index */
175
 
176
__externC char *
177
__index( const char *s, int c )
178
{
179
    // Don't bother tracing - strchr can do that
180
    return strchr(s, c);
181
}
182
 
183
__externC char *
184
index( const char *s, int c ) CYGBLD_ATTRIB_WEAK_ALIAS(__index);
185
 
186
/*---------------------------------------------------------------------*/
187
/* rindex */
188
 
189
__externC char *
190
__rindex( const char *s, int c )
191
{
192
    // Don't bother tracing - strrchr can do that
193
    return strrchr(s, c);
194
}
195
 
196
__externC char *
197
rindex( const char *s, int c ) CYGBLD_ATTRIB_WEAK_ALIAS(__rindex);
198
 
199
/*---------------------------------------------------------------------*/
200
/* swab */
201
 
202
__externC void
203
__swab( const void *from, void *to, size_t n )
204
{
205
    const char *f = (const char *)from;
206
    char *t = (char *)to;
207
    size_t ptr;
208
 
209
    CYG_REPORT_FUNCNAME( "swab" );
210
    CYG_REPORT_FUNCARG3( "from=%08x, to=%08x, n=%d", from, to, n );
211
 
212
    if (n) {
213
        CYG_CHECK_DATA_PTR( from, "from is not a valid pointer!" );
214
        CYG_CHECK_DATA_PTR( to, "to is not a valid pointer!" );
215
    }
216
 
217
    for (ptr = 1; ptr < n; ptr += 2)
218
    {
219
        char p = f[ptr];
220
        char q = f[ptr-1];
221
        t[ptr-1] = p;
222
        t[ptr  ] = q;
223
    }
224
    if (ptr == n)          /* I.e., if n is odd, */
225
        t[ptr-1] = '\0';   /* then pad with a NUL. */
226
 
227
    CYG_REPORT_RETURN();
228
}
229
 
230
__externC void
231
swab( const void *from, void *to, size_t n ) \
232
  CYGBLD_ATTRIB_WEAK_ALIAS(__swab);
233
 
234
/*---------------------------------------------------------------------*/
235
// EOF bsdstring.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.